summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nicoletti <mirttex85-pk@yahoo.com.br>2008-07-07 00:41:28 -0300
committerDaniel Nicoletti <mirttex85-pk@yahoo.com.br>2008-07-07 00:41:28 -0300
commitb770c065a7f9e4dcf28f813b0870acd20dded2f1 (patch)
tree4755ea71d7b517426af3dce31289414a1c388a9b
parent8d7602dc26b223f6653d541544da58cc3b343756 (diff)
Beta3 - lib now fully working with polkit and Kded module checking for updates
-rw-r--r--gui/KPackageKitD/kpackagekitd.cpp57
-rw-r--r--gui/KPackageKitD/kpackagekitd.h18
-rw-r--r--gui/Settings/CMakeLists.txt2
-rw-r--r--gui/Settings/PkConfigSkell.cpp28
-rw-r--r--gui/Settings/PkConfigSkell.h33
-rwxr-xr-xgui/Settings/PkSettings.cpp59
-rwxr-xr-xgui/Settings/PkSettings.h14
-rw-r--r--gui/Settings/PkSettings.ui54
-rwxr-xr-xgui/Updater/PkUpdate.cpp29
-rwxr-xr-xgui/Updater/PkUpdate.h6
-rw-r--r--lib/CMakeLists.txt3
-rw-r--r--lib/Daemon.cpp16
-rw-r--r--lib/PolkitClient.cpp37
-rw-r--r--lib/Transaction.cpp222
14 files changed, 302 insertions, 276 deletions
diff --git a/gui/KPackageKitD/kpackagekitd.cpp b/gui/KPackageKitD/kpackagekitd.cpp
index eb94a09..605ed05 100644
--- a/gui/KPackageKitD/kpackagekitd.cpp
+++ b/gui/KPackageKitD/kpackagekitd.cpp
@@ -18,38 +18,55 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include "kpackagekitd.h"
+
#include <KGenericFactory>
#include <KStandardDirs>
#include <KConfigGroup>
#include <QDateTime>
-
-#include <KMessageBox>
#include <limits.h>
-#include "kpackagekitd.h"
-K_PLUGIN_FACTORY(KPackageKitFactory, registerPlugin<KPackageKit>(); )
+#define TEN_MIN 600000
+
+K_PLUGIN_FACTORY(KPackageKitFactory, registerPlugin<KPackageKitD>(); )
K_EXPORT_PLUGIN(KPackageKitFactory("kpackagekitd"))
-KPackageKit::KPackageKit(QObject *parent, const QList<QVariant>&)
+KPackageKitD::KPackageKitD(QObject *parent, const QList<QVariant>&)
: KDEDModule(parent)
{
m_qtimer = new QTimer(this);
connect( m_qtimer, SIGNAL( timeout() ), this, SLOT( init() ) ) ;
// Start after 10 minutes, 600000 msec
// To keep the startup fast..
- m_qtimer->start(600000);
+ m_qtimer->start(TEN_MIN);
}
-KPackageKit::~KPackageKit()
+KPackageKitD::~KPackageKitD()
{
}
-void KPackageKit::init()
+void KPackageKitD::init()
{
m_qtimer->stop();
m_qtimer->disconnect();
connect( m_qtimer, SIGNAL( timeout() ), this, SLOT( read() ) );
+
+ // Create a new daemon
+ m_daemon = new Daemon(this);
+
+ uint actions = m_daemon->getActions();
+
+ if ( !(actions & Actions::Refresh_cache) ) {
+ //if the backend does not suport refreshing cache let's don't do nothing
+ return;
+ }
+
+ m_pkClient_updates = m_daemon->newTransaction();
+// connect( m_pkClient_updates, SIGNAL(GotPackage(Package *)), m_pkg_model_updates, SLOT(addPackage(Package *)) );
+ connect( m_pkClient_updates, SIGNAL( Finished(Exit::Value, uint)), this, SLOT( Finished(Exit::Value, uint) ) );
+
read();
+
//check if any changes to the file occour
//this also prevents from reading when a checkUpdate happens
m_confWatch = new KDirWatch(this);
@@ -60,7 +77,7 @@ void KPackageKit::init()
m_confWatch->startScan();
}
-void KPackageKit::read()
+void KPackageKitD::read()
{
KConfig config("KPackageKit");
KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
@@ -78,21 +95,33 @@ void KPackageKit::read()
//interval - (now - lastCheck)
//Schedule for msecs...
//check first to see any overflow...
- if ( (now - lastCheck - interval) > 4294966 )
+ if ( (interval + lastCheck - now) > 4294966 )
m_qtimer->start( UINT_MAX );
else
- m_qtimer->start( (now - lastCheck - interval) * 1000 );
+ m_qtimer->start( (interval + lastCheck - now) * 1000 );
}
}
-void KPackageKit::write()
+void KPackageKitD::write()
{
KConfig config("KPackageKit");
KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
checkUpdateGroup.writeEntry( "lastChecked", QDateTime::currentDateTime().toTime_t() );
}
-void KPackageKit::checkUpdates()
+void KPackageKitD::Finished(Exit::Value status, uint)
+{
+ if ( status == Exit::Success )
+ write();
+ else
+ // try again in 10 minutes
+ m_qtimer->start(TEN_MIN);
+}
+
+
+void KPackageKitD::checkUpdates()
{
-// KMessageBox::questionYesNo( 0, tr("Local ") + KStandardDirs::locateLocal("config", "KPackageKit") , "Rest?");
+ if ( !m_pkClient_updates->refreshCache(true) )
+ // try again in 10 minutes
+ m_qtimer->start(TEN_MIN);
}
diff --git a/gui/KPackageKitD/kpackagekitd.h b/gui/KPackageKitD/kpackagekitd.h
index 210bb9e..7f9cf58 100644
--- a/gui/KPackageKitD/kpackagekitd.h
+++ b/gui/KPackageKitD/kpackagekitd.h
@@ -18,28 +18,36 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#ifndef KPACKAGEKIT_H
-#define KPACKAGEKIT_H
+#ifndef KPACKAGEKITD_H
+#define KPACKAGEKITD_H
#include <KDEDModule>
#include <KDirWatch>
#include <QTimer>
+#include <QPackageKit>
-class KPackageKit : public KDEDModule
+using namespace PackageKit;
+
+class KPackageKitD : public KDEDModule
{
Q_OBJECT
public:
- KPackageKit(QObject *parent, const QList<QVariant>&);
- ~KPackageKit();
+ KPackageKitD(QObject *parent, const QList<QVariant>&);
+ ~KPackageKitD();
+
private:
QTimer *m_qtimer;
KDirWatch *m_confWatch;
+ Daemon *m_daemon;
+ Transaction *m_pkClient_updates;
+
private slots:
void init();
void read();
void write();
void checkUpdates();
+ void Finished(Exit::Value, uint);
};
#endif
diff --git a/gui/Settings/CMakeLists.txt b/gui/Settings/CMakeLists.txt
index 9762ed0..befd9e7 100644
--- a/gui/Settings/CMakeLists.txt
+++ b/gui/Settings/CMakeLists.txt
@@ -7,6 +7,6 @@ kde4_add_ui_files(kpk_settings_SRCS
)
kde4_add_plugin(kcm_kpk_settings ${kpk_settings_SRCS})
-target_link_libraries(kcm_kpk_settings ${KDE4_KDEUI_LIBS})
+target_link_libraries(kcm_kpk_settings ${KDE4_KDEUI_LIBS} ${QPACKAGEKIT_LIB})
install(TARGETS kcm_kpk_settings DESTINATION ${PLUGIN_INSTALL_DIR} )
diff --git a/gui/Settings/PkConfigSkell.cpp b/gui/Settings/PkConfigSkell.cpp
deleted file mode 100644
index f457f01..0000000
--- a/gui/Settings/PkConfigSkell.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2008 by Daniel Nicoletti *
- * dantti85-pk@yahoo.com.br *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ***************************************************************************/
-
-#include "PkConfigSkell.h"
-
-PkConfigSkell::PkConfigSkell()
-{
- setCurrentGroup("SmartIcon");
- addItemBool("notify", notify, true);
- addItemBool("longTask", longTask, true);
-}
diff --git a/gui/Settings/PkConfigSkell.h b/gui/Settings/PkConfigSkell.h
deleted file mode 100644
index 20f4bc3..0000000
--- a/gui/Settings/PkConfigSkell.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2008 by Daniel Nicoletti *
- * dantti85-pk@yahoo.com.br *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ***************************************************************************/
-
-#include <KConfigSkeleton>
-
-#ifndef PKCONFIGSKELL_H
-#define PKCONFIGSKELL_H
-
-class PkConfigSkell : public KConfigSkeleton
-{
-public:
- PkConfigSkell();
- bool notify, longTask;
-};
-
-#endif
diff --git a/gui/Settings/PkSettings.cpp b/gui/Settings/PkSettings.cpp
index 12cbd0e..059330a 100755
--- a/gui/Settings/PkSettings.cpp
+++ b/gui/Settings/PkSettings.cpp
@@ -21,32 +21,52 @@
#include "PkSettings.h"
#include <KDebug>
#include <KConfig>
-#include <KGlobal>
-
-// 1 Hour = 3600 in Epoch
-// 1 Day = 86400 in Epoch (24 Hours)
-// 1 Week = 604800 in Epoch (7 Days / 168 Hours)
-// 1 Month = 2628000 in Epoch
+#include <KLocale>
+#define HOURLY 3600
+#define DAILY 86400
+#define WEEKLY 604800
+#define MONTHLY 2628000
+#define NEVER 0
PkSettings::PkSettings( QWidget *parent ) : QWidget( parent )
{
setupUi( this );
-// m_kcfDM = new KConfigDialogManager(this, m_pk_cfgSkell = new PkConfigSkell());
- connect( notifyUpdatesCB, SIGNAL(stateChanged(int)), this, SLOT(checkChanges(int)) );
- connect( notifyLongTasksCB, SIGNAL(stateChanged(int)), this, SLOT(checkChanges(int)) );
+
+ // Create a new daemon
+ m_daemon = new Daemon(this);
+
+ uint actions = m_daemon->getActions();
+
+ if ( !(actions & Actions::Refresh_cache) ) {
+ intervalL->setEnabled(false);
+ intervalCB->setEnabled(false);
+ }
+
+ intervalCB->addItem(i18n("Hourly"), HOURLY );
+ intervalCB->addItem(i18n("Daily"), DAILY );
+ intervalCB->addItem(i18n("Weekly"), WEEKLY );
+ intervalCB->addItem(i18n("Monthly"), MONTHLY );
+ intervalCB->addItem(i18n("Never"), NEVER );
+
+ connect( notifyUpdatesCB, SIGNAL( stateChanged(int) ), this, SLOT( checkChanges(int) ) );
+ connect( notifyLongTasksCB, SIGNAL( stateChanged(int) ), this, SLOT( checkChanges(int) ) );
+ connect( intervalCB, SIGNAL( currentIndexChanged(int) ), this, SLOT( checkChanges(int) ) );
}
void PkSettings::checkChanges(int)
{
- kDebug() << "checkChanges " << notifyUpdatesCB->checkState();
KConfig config("KPackageKit");
KConfigGroup smartIconGroup( &config, "SmartIcon" );
+ KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
if ( notifyUpdatesCB->checkState() !=
(Qt::CheckState) smartIconGroup.readEntry( "notifyUpdatesCB", (int) Qt::Checked)
||
notifyLongTasksCB->checkState() !=
- (Qt::CheckState) smartIconGroup.readEntry( "notifyLongTasksCB", (int) Qt::Checked) )
+ (Qt::CheckState) smartIconGroup.readEntry( "notifyLongTasksCB", (int) Qt::Checked)
+ ||
+ intervalCB->itemData( intervalCB->currentIndex() ).toUInt() !=
+ (uint) checkUpdateGroup.readEntry( "interval", DAILY ) )
emit(changed(true));
else
emit(changed(false));
@@ -54,30 +74,39 @@ void PkSettings::checkChanges(int)
void PkSettings::load()
{
- kDebug() << "load";
KConfig config("KPackageKit");
KConfigGroup smartIconGroup( &config, "SmartIcon" );
notifyUpdatesCB->setCheckState( (Qt::CheckState) smartIconGroup.readEntry( "notifyUpdatesCB",
(int) Qt::Checked) );
notifyLongTasksCB->setCheckState( (Qt::CheckState) smartIconGroup.readEntry( "notifyLongTasksCB",
(int) Qt::Checked) );
+ KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
+ uint interval = checkUpdateGroup.readEntry( "interval", DAILY );
+ int ret = intervalCB->findData(interval);
+ if ( ret == -1 ) {
+ // this is if someone change the file by hand...
+ intervalCB->addItem( KGlobal::locale()->formatDuration(interval * 1000), interval );
+ intervalCB->setCurrentIndex( intervalCB->count() - 1 );
+ }
+ else
+ intervalCB->setCurrentIndex(ret);
}
void PkSettings::save()
{
- kDebug() << "save";
KConfig config("KPackageKit");
KConfigGroup smartIconGroup( &config, "SmartIcon" );
smartIconGroup.writeEntry( "notifyUpdatesCB", (int) notifyUpdatesCB->checkState() );
smartIconGroup.writeEntry( "notifyLongTasksCB", (int) notifyLongTasksCB->checkState() );
-config.sync();
+ KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
+ checkUpdateGroup.writeEntry( "interval", intervalCB->itemData( intervalCB->currentIndex() ).toUInt() );
}
void PkSettings::defaults()
{
- kDebug() << "defaults";
notifyUpdatesCB->setCheckState(Qt::Checked);
notifyLongTasksCB->setCheckState(Qt::Checked);
+ intervalCB->setCurrentIndex( intervalCB->findData(DAILY) );
emit(checkChanges(0));
}
diff --git a/gui/Settings/PkSettings.h b/gui/Settings/PkSettings.h
index 685cd8d..09f534f 100755
--- a/gui/Settings/PkSettings.h
+++ b/gui/Settings/PkSettings.h
@@ -21,9 +21,12 @@
#ifndef PKSETTINGS_H
#define PKSETTINGS_H
-#include <kconfigdialogmanager.h>
-// #include "PkConfigSkell.h"
+#include <KConfigDialogManager>
+#include <QPackageKit>
+
#include "ui_PkSettings.h"
+
+using namespace PackageKit;
class PkSettings : public QWidget, public Ui::PkSettings
{
@@ -31,17 +34,18 @@ Q_OBJECT
public:
PkSettings( QWidget *parent=0 );
+
public slots:
void load();
void save();
void defaults();
void checkChanges(int state);
+
signals:
void changed(bool state);
-// public:
-// KConfigDialogManager *m_kcfDM;
-// PkConfigSkell *m_pk_cfgSkell;
+private:
+ Daemon *m_daemon;
};
#endif
diff --git a/gui/Settings/PkSettings.ui b/gui/Settings/PkSettings.ui
index c6f49a5..96391ed 100644
--- a/gui/Settings/PkSettings.ui
+++ b/gui/Settings/PkSettings.ui
@@ -26,53 +26,34 @@
</property>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
- <widget class="QLabel" name="label_2" >
+ <widget class="QLabel" name="intervalL" >
<property name="text" >
<string>Check for Updates:</string>
</property>
</widget>
</item>
- <item row="0" column="2" >
- <widget class="QComboBox" name="comboBox" >
+ <item row="0" column="1" colspan="2" >
+ <widget class="QComboBox" name="intervalCB" >
<property name="currentIndex" >
- <number>1</number>
+ <number>-1</number>
</property>
- <item>
- <property name="text" >
- <string>Hourly</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Daily</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Weekly</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Monthly</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>Never</string>
- </property>
- </item>
</widget>
</item>
- <item row="1" column="0" colspan="2" >
+ <item row="1" column="0" >
<widget class="QLabel" name="label_3" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
<property name="text" >
<string>Automatically Install:</string>
</property>
</widget>
</item>
- <item row="1" column="2" >
- <widget class="QComboBox" name="comboBox_2" >
+ <item row="1" column="1" colspan="2" >
+ <widget class="QComboBox" name="autoCB" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
<item>
<property name="text" >
<string>Security Only</string>
@@ -101,6 +82,9 @@
<layout class="QGridLayout" name="gridLayout_2" >
<item row="0" column="0" >
<widget class="QCheckBox" name="notifyUpdatesCB" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
<property name="text" >
<string>Notify when updates are avaliable</string>
</property>
@@ -114,6 +98,9 @@
</item>
<item row="1" column="0" >
<widget class="QCheckBox" name="notifyLongTasksCB" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
<property name="text" >
<string>Notify when long tasks have been completed</string>
</property>
@@ -127,6 +114,9 @@
</item>
<item row="2" column="0" >
<widget class="KEditListBox" name="keditlistbox" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
<property name="title" >
<string>Packages Sources</string>
</property>
diff --git a/gui/Updater/PkUpdate.cpp b/gui/Updater/PkUpdate.cpp
index a30bbfb..16b56a2 100755
--- a/gui/Updater/PkUpdate.cpp
+++ b/gui/Updater/PkUpdate.cpp
@@ -36,11 +36,11 @@ PkUpdate::PkUpdate( QWidget *parent ) : QWidget( parent )
m_daemon = new Daemon(this);
m_pkClient_updates = m_daemon->newTransaction();
- connect( m_pkClient_updates, SIGNAL(GotPackage(Package *)), m_pkg_model_updates, SLOT(addPackage(Package *)) );
- connect( m_pkClient_updates, SIGNAL(Finished(Exit::Value, uint)), this, SLOT(Finished(Exit::Value, uint)) );
- connect( m_pkClient_updates, SIGNAL(Files(Package *, QStringList)), this, SLOT(Files(Package *, QStringList)) );
- connect( m_pkClient_updates, SIGNAL( Message(const QString&, const QString&) ), this, SLOT( Message(const QString&, const QString&) ) );
- connect( m_pkClient_updates, SIGNAL( ErrorCode(const QString&, const QString&) ), this, SLOT( Message(const QString&, const QString&) ) );
+ connect( m_pkClient_updates, SIGNAL( GotPackage(Package *) ), m_pkg_model_updates, SLOT( addPackage(Package *) ) );
+// connect( m_pkClient_updates, SIGNAL(Finished(Exit::Value, uint)), this, SLOT(Finished(Exit::Value, uint)) );
+// connect( m_pkClient_updates, SIGNAL(Files(Package *, QStringList)), this, SLOT(Files(Package *, QStringList)) );
+// connect( m_pkClient_updates, SIGNAL( Message(const QString&, const QString&) ), this, SLOT( Message(const QString&, const QString&) ) );
+// connect( m_pkClient_updates, SIGNAL( ErrorCode(const QString&, const QString&) ), this, SLOT( Message(const QString&, const QString&) ) );
m_pkClient_updates->getUpdates("none");
}
@@ -51,16 +51,23 @@ void PkUpdate::on_updatePB_clicked()
void PkUpdate::on_refreshPB_clicked()
{
- qDebug() << "refresh";
Transaction *m_trans = m_daemon->newTransaction();
- /* if (*/ m_trans->refreshCache(true);/* ) {*/
+ if ( m_trans->refreshCache(true) ) {
PkTransaction *frm = new PkTransaction(m_trans, i18n("Refresh Cache"), this);
- connect( frm, SIGNAL( Finished(bool) ), this, SLOT( remFinished(bool) ) );
+ connect( frm, SIGNAL( Finished(bool) ), this, SLOT( refreshCacheFinished(bool) ) );
frm->show();
-// }
-// else
-// KMessageBox::error( this, i18n("Authentication failed"), i18n("KPackageKit") );
+ }
+ else
+ KMessageBox::error( this, i18n("Authentication failed"), i18n("KPackageKit") );
+}
+void PkUpdate::refreshCacheFinished(bool error)
+{
+ if (!error) {
+ KConfig config("KPackageKit");
+ KConfigGroup checkUpdateGroup( &config, "CheckUpdate" );
+ checkUpdateGroup.writeEntry( "lastChecked", QDateTime::currentDateTime().toTime_t() );
+ }
}
void PkUpdate::on_historyPB_clicked()
diff --git a/gui/Updater/PkUpdate.h b/gui/Updater/PkUpdate.h
index 9aa744d..1f772b0 100755
--- a/gui/Updater/PkUpdate.h
+++ b/gui/Updater/PkUpdate.h
@@ -21,10 +21,11 @@
#ifndef PKUPDATE_H
#define PKUPDATE_H
+#include <QPackageKit>
+
#include "PkAddRm_Model.h"
#include "PkAddRm_Delegate.h"
#include "ui_PkUpdate.h"
-#include <QPackageKit>
using namespace PackageKit;
@@ -33,10 +34,13 @@ class PkUpdate : public QWidget, public Ui::PkUpdate
Q_OBJECT
public:
PkUpdate( QWidget *parent=0 );
+
private slots:
void on_updatePB_clicked();
void on_refreshPB_clicked();
void on_historyPB_clicked();
+ void refreshCacheFinished(bool error);
+
private:
PkAddRmModel *m_pkg_model_updates;
PkAddRmDelegate *pkg_delegate;
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index a70403f..59acc59 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -12,7 +12,7 @@ find_package(Qt4 REQUIRED)
add_definitions(${QT_DEFINITIONS})
include(FindPkgConfig)
-pkg_check_modules(POLKIT polkit-dbus polkit-grant)
+pkg_check_modules(POLKIT polkit-dbus)
include_directories(
${QT_INCLUDES}
@@ -54,7 +54,6 @@ set_target_properties( packagekit-qt PROPERTIES VERSION 0.1 SOVERSION 0 )
target_link_libraries(packagekit-qt
${QT_QTCORE_LIBRARY}
polkit-dbus
- polkit-grant
)
install(TARGETS
diff --git a/lib/Daemon.cpp b/lib/Daemon.cpp
index b2065a6..e9c7f22 100644
--- a/lib/Daemon.cpp
+++ b/lib/Daemon.cpp
@@ -67,12 +67,16 @@ bool Daemon::getNetworkState() {
}
bool Daemon::setProxy(const QString &http_proxy, const QString &ftp_proxy) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_SETPROXY))
- proxy->SetProxy(http_proxy, ftp_proxy);
- else
- return false;
- return true;
+ // hopefully do the operation first time
+ if ( proxy->SetProxy(http_proxy, ftp_proxy).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_SETPROXY) )
+ return proxy->SetProxy(http_proxy, ftp_proxy).isValid();
+ else
+ return false;
+ }
}
void Daemon::suggestQuit() {
diff --git a/lib/PolkitClient.cpp b/lib/PolkitClient.cpp
index 6d3b85c..c386580 100644
--- a/lib/PolkitClient.cpp
+++ b/lib/PolkitClient.cpp
@@ -1,4 +1,3 @@
-#include <polkit-grant/polkit-grant.h>
#include <polkit-dbus/polkit-dbus.h>
#include "PolkitClient.h"
@@ -10,36 +9,14 @@ PolkitClient::PolkitClient(QObject *parent) : QObject(parent) {
}
bool PolkitClient::getAuth(const QString &action) {
-// DBusError e;
-// dbus_error_init(&e);
-
-// PolKitAction *p_action = polkit_action_new();
- PolKitAction *p_action = polkit_action_new_from_string_representation("org.freedesktop.packagekit.refresh-cache");
-
-// if ( !polkit_action_set_action_id( p_action, "org.freedesktop.packagekit.refresh-cache" ) ) {
-// qDebug() << "polkit action false";
-// }
- qDebug() << "validade" << polkit_action_validate_id("org.freedesktop.packagekit.refresh-cache");
- qDebug() << "check_auth" << polkit_check_auth( QCoreApplication::applicationPid(), "org.freedesktop.packagekit.refresh-cache" );
-// return true;
-// bool auth = polkit_auth_obtain(action.toAscii().data(), 0, QCoreApplication::applicationPid(), &e);
-// if(!auth) {
-// qDebug() << "Authentification error :" << e.name << ":" << e.message;
-// }
+ DBusError e;
+ dbus_error_init(&e);
- PolKitGrant *p_auth = polkit_grant_new();
-
-
-
- PolKitCaller *p_caller = polkit_caller_new();
-
- if ( !polkit_caller_set_pid( p_caller, QCoreApplication::applicationPid() ) ){
- qDebug() << "polkit caller false";
- }
-
-// polkit_grant_set_functions(p_auth);
- return polkit_grant_initiate_auth(p_auth, p_action, p_caller);
+ bool auth = polkit_auth_obtain(action.toAscii().data(), 0, QCoreApplication::applicationPid(), &e);
+ if(!auth) {
+ qDebug() << "Authentification error :" << e.name << ":" << e.message;
+ }
-// return auth;
+ return auth;
}
diff --git a/lib/Transaction.cpp b/lib/Transaction.cpp
index 3709df5..75ee2ab 100644
--- a/lib/Transaction.cpp
+++ b/lib/Transaction.cpp
@@ -130,16 +130,19 @@ void Transaction::resolve(const QString &filter, Package *p) {
}
bool Transaction::installPackages(const QList<Package*> &packages) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_INSTALL)) {
- renewTid();
- QStringList pids;
- for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
- proxy->InstallPackages(pids);
+ renewTid();
+ QStringList pids;
+ for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
+ // hopefully do the operation first time
+ if ( proxy->InstallPackages(pids).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_INSTALL) )
+ return proxy->InstallPackages(pids).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::installPackage(Package *p) {
@@ -149,64 +152,79 @@ bool Transaction::installPackage(Package *p) {
}
bool Transaction::installSignature(const SignatureType::Value &type, const QString &key_id, Package *p) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_INSTALLSIGNATURE)) {
- renewTid();
- proxy->InstallSignature(EnumToString<SignatureType>(type), key_id, p->id());
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->InstallSignature(EnumToString<SignatureType>(type), key_id, p->id()).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_INSTALLSIGNATURE) )
+ return proxy->InstallSignature(EnumToString<SignatureType>(type), key_id, p->id()).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::updatePackages(const QList<Package*> &packages) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_UPDATEPACKAGE)) {
- renewTid();
- QStringList pids;
- for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
- proxy->UpdatePackages(pids);
+ renewTid();
+ QStringList pids;
+ for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
+ // hopefully do the operation first time
+ if ( proxy->UpdatePackages(pids).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_UPDATEPACKAGE) )
+ return proxy->UpdatePackages(pids).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::updatePackage(Package *p) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_UPDATEPACKAGE)) {
- renewTid();
- QStringList pids;
- pids << p->id();
- proxy->UpdatePackages(pids);
+ renewTid();
+ QStringList pids;
+ pids << p->id();
+ // hopefully do the operation first time
+ if ( proxy->UpdatePackages(pids).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_UPDATEPACKAGE) )
+ return proxy->UpdatePackages(pids).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::installFiles(const QStringList& files, bool trusted) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth((trusted ? AUTH_LOCALINSTALLTRUSTED : AUTH_LOCALINSTALLUNTRUSTED))) {
- renewTid();
- proxy->InstallFiles(trusted, files);
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->InstallFiles(trusted, files).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth((trusted ? AUTH_LOCALINSTALLTRUSTED : AUTH_LOCALINSTALLUNTRUSTED)) )
+ return proxy->InstallFiles(trusted, files).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::removePackages(const QList<Package*> &packages, bool allow_deps, bool autoremove) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_REMOVE)) {
- renewTid();
- QStringList pids;
- for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
- proxy->RemovePackages(pids, allow_deps, autoremove);
+ renewTid();
+ QStringList pids;
+ for(int i = 0 ; i < packages.size() ; ++i) pids << packages.at(i)->id();
+ // hopefully do the operation first time
+ if ( proxy->RemovePackages(pids, allow_deps, autoremove).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_REMOVE) )
+ return proxy->RemovePackages(pids, allow_deps, autoremove).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::removePackage(Package *p, bool allow_deps, bool autoremove) {
@@ -216,25 +234,31 @@ bool Transaction::removePackage(Package *p, bool allow_deps, bool autoremove) {
}
bool Transaction::updateSystem() {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_UPDATESYSTEM)) {
- renewTid();
- proxy->UpdateSystem();
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->UpdateSystem().isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_UPDATESYSTEM) )
+ return proxy->UpdateSystem().isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::rollback(const QString &tid) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_ROLLBACK)) {
- renewTid();
- proxy->Rollback(tid);
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->Rollback(tid).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_ROLLBACK) )
+ return proxy->Rollback(tid).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
void Transaction::getUpdates(const QString& filter) {
@@ -248,14 +272,17 @@ void Transaction::getUpdateDetail(const QString& package_id) {
}
bool Transaction::refreshCache(bool force) {
- qDebug() << "Trying to get authorization...";
-// if (polkit->getAuth(AUTH_REFRESHCACHE)) {
- renewTid();
- proxy->RefreshCache(force);
-// }
-// else
-// return false;
- return true;
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->RefreshCache(force).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_REFRESHCACHE) )
+ return proxy->RefreshCache(force).isValid();
+ else
+ return false;
+ }
}
void Transaction::getProgress(uint &percentage, uint &subpercentage, uint &elapsed, uint &remaining) {
@@ -268,25 +295,31 @@ void Transaction::getRepoList(const QString &filter) {
}
bool Transaction::repoEnable(const QString &repo_id, bool enabled) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_REPOCHANGE)) {
- renewTid();
- proxy->RepoEnable(repo_id, enabled);
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->RepoEnable(repo_id, enabled).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_REPOCHANGE) )
+ return proxy->RepoEnable(repo_id, enabled).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::repoSetData(const QString &repo_id, const QString &parameter, const QString &value) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_REPOCHANGE)) {
- renewTid();
- proxy->RepoSetData(repo_id, parameter, value);
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->RepoSetData(repo_id, parameter, value).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_REPOCHANGE) )
+ return proxy->RepoSetData(repo_id, parameter, value).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
bool Transaction::isCallerActive() {
@@ -300,14 +333,17 @@ void Transaction::getOldTransactions(uint number) {
}
bool Transaction::acceptEula(const QString &id) {
- qDebug() << "Trying to get authorization...";
- if (polkit->getAuth(AUTH_ACCEPTEULA)) {
- renewTid();
- proxy->AcceptEula(id);
+ renewTid();
+ // hopefully do the operation first time
+ if ( proxy->AcceptEula(id).isValid() )
+ return true;
+ else {
+ // ok no lucky...
+ if ( polkit->getAuth(AUTH_ACCEPTEULA) )
+ return proxy->AcceptEula(id).isValid();
+ else
+ return false;
}
- else
- return false;
- return true;
}
// Signal callbacks