[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase
From: Dario Freddi <drf () kde ! org>
Date: 2009-08-31 10:14:07
Message-ID: 1251713647.708701.5706.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1017737 by dafre:
CCMAIL: nicola.gigante@gmail.com
Merging the new systemsettings and the ported kcmdatetime module
_M . (directory)
M +4 -6 workspace/kcontrol/dateandtime/CMakeLists.txt
M +10 -7 workspace/kcontrol/dateandtime/dtime.cpp
M +1 -1 workspace/kcontrol/dateandtime/dtime.h
M +41 -79 workspace/kcontrol/dateandtime/helper.cpp
M +30 -11 workspace/kcontrol/dateandtime/helper.h
A workspace/kcontrol/dateandtime/kcmclock_actions.ini \
branches/work/kdebase-libkauth/workspace/kcontrol/dateandtime/kcmclock_actions.ini#1017692
M +20 -24 workspace/kcontrol/dateandtime/main.cpp
M +5 -4 workspace/kcontrol/dateandtime/tzone.cpp
M +1 -1 workspace/kcontrol/dateandtime/tzone.h
M +33 -9 workspace/systemsettings/core/ModuleView.cpp
M +6 -1 workspace/systemsettings/core/ModuleView.h
** trunk/KDE/kdebase #property svnmerge-integrated
+ /trunk/KDE/kdebase:1-1017600
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/CMakeLists.txt #1017736:1017737
@@ -1,11 +1,10 @@
+include(MacroKAuth)
-
########### next target ###############
set(kcm_clock_PART_SRCS dtime.cpp tzone.cpp main.cpp )
-
kde4_add_plugin(kcm_clock ${kcm_clock_PART_SRCS})
@@ -15,11 +14,10 @@
########### next target ###############
-set(kcmdatetimehelper_SRCS helper.cpp)
-kde4_add_executable(kcmdatetimehelper ${kcmdatetimehelper_SRCS})
-target_link_libraries(kcmdatetimehelper ${KDE4_KDECORE_LIBS} )
-install(TARGETS kcmdatetimehelper DESTINATION ${LIBEXEC_INSTALL_DIR})
+kde4_auth_add_helper(kcmdatetimehelper org.kde.kcontrol.kcmclock root helper.cpp \
${helper_mocs})
+kde4_auth_register_actions(org.kde.kcontrol.kcmclock kcmclock_actions.ini)
+
########### install files ###############
install( FILES clock.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/dtime.cpp #1017736:1017737
@@ -230,7 +230,7 @@
timeout();
}
-void Dtime::save( QStringList& helperargs )
+void Dtime::save( QVariantMap& helperargs )
{
// Save the order, but don't duplicate!
QStringList list;
@@ -244,8 +244,10 @@
if( list.count() == 10)
break;
}
- helperargs << "ntp" << QString::number( list.count()) << list
- << ( setDateTimeAuto->isChecked() ? "enabled" : "disabled" );
+
+ helperargs["ntp"] = true;
+ helperargs["ntpServers"] = list;
+ helperargs["ntpEnabled"] = setDateTimeAuto->isChecked();
if(setDateTimeAuto->isChecked() && !ntpUtility.isEmpty()){
// NTP Time setting - done in helper
@@ -258,8 +260,9 @@
kDebug() << "Set date " << dt;
- helperargs << "date" << QString::number(dt.toTime_t())
- << QString::number(::time(0));
+ helperargs["date"] = true;
+ helperargs["newdate"] = QString::number(dt.toTime_t());
+ helperargs["olddate"] = QString::number(::time(0));
}
// restart time
@@ -268,11 +271,11 @@
void Dtime::processHelperErrors( int code )
{
- if( code & ERROR_DTIME_NTP ) {
+ if( code & ClockHelper::NTPError ) {
KMessageBox::error( this, i18n("Unable to contact time server: %1.", timeServer) \
); setDateTimeAuto->setChecked( false );
}
- if( code & ERROR_DTIME_DATE ) {
+ if( code & ClockHelper::DateError ) {
KMessageBox::error( this, i18n("Can not set date."));
}
}
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/dtime.h #1017736:1017737
@@ -46,7 +46,7 @@
public:
Dtime( QWidget *parent=0 );
- void save( QStringList& helperargs );
+ void save( QVariantMap &helperargs );
void processHelperErrors( int code );
void load();
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/helper.cpp #1017736:1017737
@@ -40,6 +40,7 @@
#include <kstandarddirs.h>
#include <kprocess.h>
#include <QFile>
+#include <QDebug>
#if defined(USE_SOLARIS)
#include <ktemporaryfile.h>
@@ -48,8 +49,8 @@
#include <sys/stat.h>
#endif
-static int Dtime_save_ntp( const QStringList& ntpServers, bool ntpEnabled )
-{
+int ClockHelper::ntp( const QStringList& ntpServers, bool ntpEnabled )
+{
int ret = 0;
// write to the system config file
KConfig _config( KDE_CONFDIR "/kcmclockrc", KConfig::SimpleConfig);
@@ -75,26 +76,26 @@
KProcess proc;
proc << ntpUtility << timeServer;
if( proc.execute() != 0 ){
- ret |= ERROR_DTIME_NTP;
+ ret |= NTPError;
}
} else if( ntpEnabled ) {
- ret |= ERROR_DTIME_NTP;
+ ret |= NTPError;
}
return ret;
}
-static int Dtime_save_date( const QString& date, const QString& olddate )
-{
+int ClockHelper::date( const QString& newdate, const QString& olddate )
+{
struct timeval tv;
- tv.tv_sec = date.toULong() - olddate.toULong() + time(0);
+ tv.tv_sec = newdate.toULong() - olddate.toULong() + time(0);
tv.tv_usec = 0;
- return settimeofday(&tv, 0) ? ERROR_DTIME_DATE : 0;
+ return settimeofday(&tv, 0) ? DateError : 0;
}
// on non-Solaris systems which do not use /etc/timezone?
-static int Tzone_save_set( const QString& selectedzone )
-{
+int ClockHelper::tz( const QString& selectedzone )
+{
int ret = 0;
#if defined(USE_SOLARIS) // MARCO
@@ -172,11 +173,11 @@
{
if (!QFile::remove("/etc/localtime"))
{
- ret |= ERROR_TZONE;
+ ret |= TimezoneError;
}
else
if (!QFile::copy(tz,"/etc/localtime"))
- ret |= ERROR_TZONE;
+ ret |= TimezoneError;
}
QFile fTimezoneFile("/etc/timezone");
@@ -197,8 +198,8 @@
return ret;
}
-static int Tzone_save_reset()
-{
+int ClockHelper::tzreset()
+{
#if !defined(USE_SOLARIS) // Do not update the System!
unlink( "/etc/timezone" );
unlink( "/etc/localtime" );
@@ -209,72 +210,33 @@
return 0;
}
-
-int main( int argc, char* argv[] )
-{
- if( getuid() != 0 ) {
- fprintf( stderr, "Needs to be called as root.\n" );
- return ERROR_CALL;
- }
- bool ntp = false;
- QStringList ntpServerList;
- bool ntpEnabled = false;
- bool date = false;
- QString datestr;
- QString olddatestr;
- bool tz = false;
- QString timezone;
- bool tzreset = false;
- QStringList args;
- for( int pos = 1;
- pos < argc;
- ++pos )
- args.append( argv[ pos ] ); // convert to QStringList first to protect against \
possible overflows
- while( !args.isEmpty()) {
- QString arg = args.takeFirst();
- if( arg == "ntp" && !args.isEmpty()) {
- int ntpCount = args.takeFirst().toInt();
- if( ntpCount >= 0 && ntpCount <= args.count()) {
- for( int i = 0;
- i < ntpCount;
- ++i ) {
- ntpServerList.append( args.takeFirst());
- }
- }
- if( args.isEmpty()) {
- fprintf( stderr, "Wrong arguments!\n" );
- exit( ERROR_CALL );
- }
- ntpEnabled = args.takeFirst() == "enabled";
- ntp = true;
- } else if( arg == "date" && !args.isEmpty()) {
- datestr = args.takeFirst();
- if( args.isEmpty()) {
- fprintf( stderr, "Wrong arguments!\n" );
- exit( ERROR_CALL );
- }
- olddatestr = args.takeFirst();
- date = true;
- } else if( arg == "tz" && !args.isEmpty()) {
- timezone = args.takeFirst();
- tz = true;
- } else if( arg == "tzreset" ) {
- tzreset = true;
- } else {
- fprintf( stderr, "Wrong arguments!\n" );
- exit( ERROR_CALL );
- }
- }
+ActionReply ClockHelper::save(const QVariantMap &args)
+{
+ bool _ntp = args.value("ntp").toBool();
+ bool _date = args.value("date").toBool();
+ bool _tz = args.value("tz").toBool();
+ bool _tzreset = args.value("tzreset").toBool();
+
KComponentData data( "kcmdatetimehelper" );
+
int ret = 0; // error code
// The order here is important
- if( ntp )
- ret |= Dtime_save_ntp( ntpServerList, ntpEnabled );
- if( date )
- ret |= Dtime_save_date( datestr, olddatestr );
- if( tz )
- ret |= Tzone_save_set( timezone );
- if( tzreset )
- ret |= Tzone_save_reset();
- return ret;
+ if( _ntp )
+ ret |= ntp( args.value("ntpServers").toStringList(), \
args.value("ntpEnabled").toBool() ); + if( _date )
+ ret |= date( args.value("newdate").toString(), args.value("olddate").toString() \
); + if( _tz )
+ ret |= tz( args.value("tzone").toString() );
+ if( _tzreset )
+ ret |= tzreset();
+
+ if (ret == 0) {
+ return ActionReply::SuccessReply;
+ } else {
+ ActionReply reply(ActionReply::HelperError);
+ reply.setErrorCode(ret);
+ return reply;
+ }
}
+
+KDE4_AUTH_HELPER_MAIN("org.kde.kcontrol.kcmclock", ClockHelper)
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/helper.h #1017736:1017737
@@ -18,9 +18,36 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
-#ifndef helper_included
-#define helper_included
+#ifndef CLOCK_HELPER_H
+#define CLOCK_HELPER_H
+#include <kauth.h>
+
+using namespace KAuth;
+
+class ClockHelper : public QObject
+{
+ Q_OBJECT
+
+ public:
+ enum
+ {
+ CallError = 1 << 0,
+ TimezoneError = 1 << 1,
+ NTPError = 1 << 2,
+ DateError = 1 << 3
+ };
+
+ public slots:
+ ActionReply save(const QVariantMap &map);
+
+ private:
+ int ntp(const QStringList& ntpServers, bool ntpEnabled);
+ int date(const QString& newdate, const QString& olddate);
+ int tz(const QString& selectedzone);
+ int tzreset();
+};
+
/*
commands:
ntp <count> <servers> <enabled/disabled>
@@ -29,12 +56,4 @@
tzreset
*/
-enum
- {
- ERROR_CALL = 1 << 0,
- ERROR_TZONE = 1 << 1,
- ERROR_DTIME_NTP = 1 << 2,
- ERROR_DTIME_DATE = 1 << 3
- };
-
-#endif // main_included
+#endif // CLOCK_HELPER_H
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/main.cpp #1017736:1017737
@@ -41,6 +41,8 @@
#include "dtime.h"
#include "helper.h"
+#include <kauthaction.h>
+
K_PLUGIN_FACTORY(KlockModuleFactory, registerPlugin<KclockModule>();)
K_EXPORT_PLUGIN(KlockModuleFactory("kcmkclock"))
@@ -79,43 +81,37 @@
setButtons(Help|Apply);
+ setNeedsAuthorization(true);
+
process = NULL;
}
void KclockModule::save()
{
- QStringList helperargs;
+ QVariantMap helperargs;
dtime->save( helperargs );
tzone->save( helperargs );
- QString helper = KStandardDirs::findExe( "kcmdatetimehelper" );
- QString kdesu = KStandardDirs::findExe( "kdesu" );
- bool ok = true;
- if( helper.isEmpty() || kdesu.isEmpty())
- ok = false;
- else {
- process = new KProcess(this);
- *process << kdesu;
- *process << "--attach" << QString::number(window()->winId()) << "--" << helper;
- *process << helperargs;
- process->start();
- connect( process, SIGNAL( finished(int, QProcess::ExitStatus) ),
- SLOT( slotDateTimeHelperFinished(int) ) );
- ok = process->waitForStarted();
- if(!ok) {
- delete process;
- process = NULL;
+
+ Action *action = authAction();
+ action->setArguments(helperargs);
+
+ ActionReply reply = action->execute();
+
+ if (reply.failed())
+ {
+ if (reply.type() == ActionReply::KAuthError) {
+ KMessageBox::error(this, i18n("Unable to authenticate/execute the action: \
%1, %2", reply.errorCode(), reply.errorDescription())); + } else {
+ dtime->processHelperErrors(reply.errorCode());
+ tzone->processHelperErrors(reply.errorCode());
}
+
}
- if( !ok )
- KMessageBox::error( this, i18n( "Failed to set system date/time/time zone."), \
i18n( "Date/Time Error" )); }
void KclockModule::slotDateTimeHelperFinished(int exitCode)
{
dtime->processHelperErrors( exitCode );
- tzone->processHelperErrors( exitCode);
-
- process->deleteLater();
- process = NULL;
+ tzone->processHelperErrors( exitCode );
#if 0
// Tell the clock applet about the change so that it can update its timezone
QDBusInterface clock("org.kde.kicker", "/Applets/Clock", \
"org.kde.kicker.ClockApplet");
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/tzone.cpp #1017736:1017737
@@ -92,16 +92,17 @@
// FIXME: Does the logic in this routine actually work correctly? For example,
// on non-Solaris systems which do not use /etc/timezone?
-void Tzone::save( QStringList& helperargs )
+void Tzone::save( QVariantMap& helperargs )
{
QStringList selectedZones(tzonelist->selection());
if (selectedZones.count() > 0)
{
QString selectedzone(selectedZones[0]);
- helperargs << "tz" << selectedzone; // make the helper set the timezone
+ helperargs["tz"] = true;
+ helperargs["tzone"] = selectedzone;
} else {
- helperargs << "tzreset"; // // make the helper reset the timezone
+ helperargs["tzreset"] = true; // // make the helper reset the timezone
}
currentZone();
@@ -109,7 +110,7 @@
void Tzone::processHelperErrors( int code )
{
- if( code & ERROR_TZONE )
+ if( code & ClockHelper::TimezoneError)
KMessageBox::error( this, i18n("Error setting new time zone."),
i18n("Time zone Error"));
}
--- trunk/KDE/kdebase/workspace/kcontrol/dateandtime/tzone.h #1017736:1017737
@@ -37,7 +37,7 @@
public:
Tzone( QWidget *parent=0 );
- void save( QStringList& helperargs );
+ void save( QVariantMap &helperargs );
void processHelperErrors( int code );
void load();
--- trunk/KDE/kdebase/workspace/systemsettings/core/ModuleView.cpp #1017736:1017737
@@ -40,6 +40,7 @@
#include <KCModuleProxy>
#include <KStandardGuiItem>
#include <KDialogButtonBox>
+#include <kauthaction.h>
#include "MenuItem.h"
@@ -71,6 +72,7 @@
// Create the dialog
d->mButtons = new KDialogButtonBox( this, Qt::Horizontal );
d->mLayout->addWidget(d->mButtons);
+
// Create the buttons in it
d->mApply = d->mButtons->addButton( KStandardGuiItem::apply(), \
QDialogButtonBox::ApplyRole );
d->mDefault = d->mButtons->addButton( KStandardGuiItem::defaults(), \
QDialogButtonBox::ResetRole ); @@ -201,19 +203,20 @@
}
// Let the user decide
+ KGuiItem applyItem = KStandardGuiItem::apply();
+ applyItem.setIcon( KIcon(d->mApply->icon()) );
const int queryUser = KMessageBox::warningYesNoCancel(
this,
i18n("The settings of the current module have changed.\n"
"Do you want to apply the changes or discard them?"),
i18n("Apply Settings"),
- KStandardGuiItem::apply(),
+ applyItem,
KStandardGuiItem::discard(),
KStandardGuiItem::cancel() );
switch (queryUser) {
case KMessageBox::Yes:
- currentProxy->save();
- return true;
+ return moduleSave(currentProxy);
case KMessageBox::No:
currentProxy->load();
@@ -251,12 +254,20 @@
blockSignals(false);
}
-void ModuleView::moduleSave()
+bool ModuleView::moduleSave()
{
- KCModuleProxy * activeModule = d->mPages.value( d->mPageWidget->currentPage() );
- if( activeModule ) {
- activeModule->save();
+ KCModuleProxy * moduleProxy = d->mPages.value( d->mPageWidget->currentPage() );
+ return moduleSave( moduleProxy );
+}
+
+bool ModuleView::moduleSave(KCModuleProxy *module)
+{
+ if( !module ) {
+ return false;
}
+
+ module->save();
+ return true;
}
void ModuleView::moduleLoad()
@@ -309,9 +320,22 @@
bool change = false;
if( activeModule ) {
change = activeModule->changed();
+
+ qDebug() << "checking";
+ if (activeModule->realModule()->authAction()) {
+ qDebug() << activeModule->realModule()->authAction()->name();
+ d->mApply->setAuthAction(activeModule->realModule()->authAction());
+ disconnect( d->mApply, SIGNAL(clicked()), this, SLOT(moduleSave()) );
+ connect( d->mApply, SIGNAL(authorized(KAuth::Action)), this, SLOT(moduleSave()) \
); + } else {
+ d->mApply->setAuthAction(0);
+ connect( d->mApply, SIGNAL(clicked()), this, SLOT(moduleSave()) );
+ disconnect( d->mApply, SIGNAL(authorized(KAuth::Action)), this, \
SLOT(moduleSave()) ); + }
}
- d->mApply->setEnabled(change);
- d->mReset->setEnabled(change);
+
+ d->mApply->setEnabled( change );
+ d->mReset->setEnabled( change );
emit moduleChanged( change );
}
--- trunk/KDE/kdebase/workspace/systemsettings/core/ModuleView.h #1017736:1017737
@@ -112,7 +112,12 @@
/**
* Causes the active module to save its configuration, applying all changes.
*/
- void moduleSave();
+ bool moduleSave();
+
+ /**
+ * Causes the specified module to save its configuration, applying all changes.
+ */
+ bool moduleSave(KCModuleProxy *module);
/**
* Causes the active module to revert all changes to the configuration, and \
return to defaults.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic