Skip to content

Commit

Permalink
Remove liboobs dependency from lxqt-admin-time and use timedatectl to…
Browse files Browse the repository at this point in the history
… handle all time configurations.
  • Loading branch information
PCMan committed Jun 18, 2016
1 parent ff6c8f1 commit 6b22c9d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 56 deletions.
2 changes: 0 additions & 2 deletions lxqt-admin-time/CMakeLists.txt
Expand Up @@ -3,7 +3,6 @@ project(lxqt-admin-time)
# build static helper class first
include_directories (
${CMAKE_CURRENT_BINARY_DIR}
${OOBS_INCLUDE_DIRS}
)

set ( lxqt-admin-time_HDRS
Expand Down Expand Up @@ -77,7 +76,6 @@ target_link_libraries(lxqt-admin-time
KF5::WindowSystem
Qt5::Widgets
lxqt
${OOBS_LIBRARIES}
)

install(TARGETS lxqt-admin-time RUNTIME DESTINATION bin)
Expand Down
47 changes: 5 additions & 42 deletions lxqt-admin-time/timeadmindialog.cpp
Expand Up @@ -39,12 +39,8 @@
#define ZONETAB_PATH "/usr/share/zoneinfo/zone.tab"

TimeAdminDialog::TimeAdminDialog(QWidget *parent):
LXQt::ConfigDialog(tr("Time and date configuration"),new LXQt::Settings("TimeDate"), parent),
mTimeConfig(OOBS_TIME_CONFIG(oobs_time_config_get())),
mUserLogedIn(false)
LXQt::ConfigDialog(tr("Time and date configuration"),new LXQt::Settings("TimeDate"), parent)
{
oobs_object_update(OOBS_OBJECT(mTimeConfig));

setMinimumSize(QSize(400,400));
mWindowTitle = windowTitle();

Expand All @@ -67,8 +63,6 @@ TimeAdminDialog::TimeAdminDialog(QWidget *parent):

TimeAdminDialog::~TimeAdminDialog()
{
if(mTimeConfig)
g_object_unref(mTimeConfig);
}

void TimeAdminDialog::onChanged(bool ch)
Expand All @@ -93,15 +87,8 @@ void TimeAdminDialog::closeEvent(QCloseEvent *event)
//save changes to system
if (mWidgetsModified)
{
if (logInUser())
{
saveChangesToSystem();
event->accept();
}
else
{
event->ignore();
}
saveChangesToSystem();
event->accept();
}
}

Expand Down Expand Up @@ -136,35 +123,11 @@ void TimeAdminDialog::saveChangesToSystem()
// FIXME: currently timezone settings does not work. is this a bug of system-tools-backend?
if(!timeZone.isEmpty() && mWidgetsModified.testFlag(M_TIMEZONE)) {
mTimeDateCtl.setTimeZone(timeZone);
mTimeDateCtl.commit();
}

if(mWidgetsModified.testFlag(M_TIMEDATE))
{
QDate d = mDateTimeWidget->dateTime().date();
QTime t = mDateTimeWidget->dateTime().time();
// oobs seems to use 0 based month
oobs_time_config_set_time(mTimeConfig, d.year(), d.month() - 1, d.day(), t.hour(), t.minute(), t.second());
}
oobs_object_commit(OOBS_OBJECT(mTimeConfig));
}

bool TimeAdminDialog::logInUser()
{
if (mUserLogedIn)
return true;

GError* err = NULL;
if(oobs_object_authenticate(OOBS_OBJECT(mTimeConfig), &err))
{
mUserLogedIn = true;
return true;
mTimeDateCtl.setDateTime(mDateTimeWidget->dateTime());
}
else if(err)
{
QMessageBox::critical(this, tr("Authentication Error"), QString::fromUtf8(err->message));
g_error_free(err);
}

return false;
mTimeDateCtl.commit();
}
8 changes: 0 additions & 8 deletions lxqt-admin-time/timeadmindialog.h
Expand Up @@ -26,13 +26,8 @@
* END_COMMON_COPYRIGHT_HEADER */

#include <LXQt/ConfigDialog>
#include <glib.h>
#include <oobs/oobs-timeconfig.h>
#include <oobs/oobs-ntpconfig.h>
#include <oobs/oobs-ntpserver.h>
#include "timedatectl.h"


class DateTime;
class Timezone;

Expand All @@ -55,17 +50,14 @@ private Q_SLOTS:
void onChanged(bool);

private:
bool logInUser();
void saveChangesToSystem();
void loadTimeZones(QStringList & timeZones, QString & currentTimezone);
void showChangedStar();

private:
TimeDateCtl mTimeDateCtl;
OobsTimeConfig* mTimeConfig;
DateTime * mDateTimeWidget;
Timezone * mTimezoneWidget;
bool mUserLogedIn;
QString mWindowTitle;
widgets_modified_t mWidgetsModified;
};
Expand Down
17 changes: 13 additions & 4 deletions lxqt-admin-time/timedatectl.cpp
Expand Up @@ -24,12 +24,21 @@ TimeDateCtl::TimeDateCtl()

bool TimeDateCtl::commit()
{
bool success = true;
QProcess timedatectl;
QStringList args;
if(mTimeZoneChanged) {
args << "set-timezone" << mTimeZone;
timedatectl.start(QStringLiteral("timedatectl"), QStringList() << "set-timezone" << mTimeZone);
timedatectl.waitForFinished();
success = timedatectl.exitCode() == 0;
}
timedatectl.start(QStringLiteral("timedatectl"), args);
timedatectl.waitForFinished();
return timedatectl.exitCode() == 0;
if(!success)
return success;

if(mTimeChanged) {
timedatectl.start(QStringLiteral("timedatectl"), QStringList() << "set-time" << mDateTime.toString("yyyy-MM-dd hh:mm:ss"));
timedatectl.waitForFinished();
success = timedatectl.exitCode() == 0;
}
return success;
}

0 comments on commit 6b22c9d

Please sign in to comment.