summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhuyaliang <[email protected]>2019-06-13 23:07:46 +0800
committerraveit65 <[email protected]>2019-06-14 12:05:04 +0200
commit0c43dc403269208f3431aebcc01dd059d3b6d48f (patch)
tree92f297c72d66e8faa4f9bf47bc5944b85619c21d
parent9c0163fd3086b66e499e44468084836320b4b912 (diff)
downloadmate-control-center-0c43dc403269208f3431aebcc01dd059d3b6d48f.tar.bz2
mate-control-center-0c43dc403269208f3431aebcc01dd059d3b6d48f.tar.xz
Authentication to add modification time
-rw-r--r--capplets/time-admin/src/main.c72
-rw-r--r--capplets/time-admin/src/time-share.h3
-rw-r--r--configure.ac5
3 files changed, 59 insertions, 21 deletions
diff --git a/capplets/time-admin/src/main.c b/capplets/time-admin/src/main.c
index b17ebc54..8b339cc2 100644
--- a/capplets/time-admin/src/main.c
+++ b/capplets/time-admin/src/main.c
@@ -14,13 +14,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include <polkit/polkit.h>
#include "time-tool.h"
#include "time-zone.h"
#include "time-map.h"
#define LOCKFILE "/tmp/time-admin.pid"
-#define TIME_ADMIN_PERMISSION "org.mate.user.admin.administration"
+#define TIME_ADMIN_PERMISSION "org.freedesktop.timedate1.set-time"
#define APPICON "mate-times-admin.png"
#define ICONFILE DATADIR APPICON
@@ -79,12 +80,36 @@ static void CloseWindow (GtkButton *button,gpointer data)
TimeAdmin *ta = (TimeAdmin *)data;
QuitApp(ta);
-}
+}
+static void UpdatePermission(TimeAdmin *ta)
+{
+ gboolean is_authorized;
+
+ is_authorized = g_permission_get_allowed (G_PERMISSION (ta->Permission));
+
+ gtk_widget_set_sensitive(ta->HourSpin, is_authorized);
+ gtk_widget_set_sensitive(ta->MinuteSpin, is_authorized);
+ gtk_widget_set_sensitive(ta->SecondSpin, is_authorized);
+ gtk_widget_set_sensitive(ta->TimeZoneButton, is_authorized);
+ gtk_widget_set_sensitive(ta->Calendar, is_authorized);
+ gtk_widget_set_sensitive(ta->SaveButton, is_authorized);
+ gtk_widget_set_sensitive(ta->NtpSyncSwitch, is_authorized);
+}
+
+
+static void on_permission_changed (GPermission *permission,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ TimeAdmin *ua = (TimeAdmin *)data;
+ UpdatePermission(ua);
+}
+
static void InitMainWindow(TimeAdmin *ta)
{
GtkWidget *Window;
GdkPixbuf *AppIcon;
- //GError *error = NULL;
+ GError *error = NULL;
Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
ta->MainWindow = WindowLogin = Window;
@@ -100,21 +125,28 @@ static void InitMainWindow(TimeAdmin *ta)
G_CALLBACK(on_window_quit),
ta);
- /*
- ua->Permission = polkit_permission_new_sync (USER_ADMIN_PERMISSION, NULL, NULL, &error);
- ua->ButtonLock = gtk_lock_button_new(ua->Permission);
- gtk_lock_button_set_permission(GTK_LOCK_BUTTON (ua->ButtonLock),ua->Permission);
- g_signal_connect(ua->Permission,
- "notify",
- G_CALLBACK (on_permission_changed),
- ua);
- */
AppIcon = GetAppIcon();
if(AppIcon)
{
gtk_window_set_icon(GTK_WINDOW(Window),AppIcon);
g_object_unref(AppIcon);
- }
+ }
+ ta->Permission = polkit_permission_new_sync (TIME_ADMIN_PERMISSION,
+ NULL,
+ NULL,
+ &error);
+ if (ta->Permission == NULL)
+ {
+ g_error_free (error);
+ return;
+ }
+ ta->ButtonLock = gtk_lock_button_new(ta->Permission);
+ gtk_lock_button_set_permission(GTK_LOCK_BUTTON (ta->ButtonLock),ta->Permission);
+ gtk_widget_grab_focus(ta->ButtonLock);
+ g_signal_connect(ta->Permission,
+ "notify",
+ G_CALLBACK (on_permission_changed),
+ ta);
}
static int RecordPid(void)
@@ -207,7 +239,6 @@ static GtkWidget * TimeZoneAndNtp(TimeAdmin *ta)
GtkWidget *table;
GtkWidget *TimeZoneLabel;
GtkWidget *NtpSyncLabel;
- GtkWidget *NtpSyncSwitch;
const char *TimeZone;
gboolean NtpState;
char *ZoneName;
@@ -236,17 +267,17 @@ static GtkWidget * TimeZoneAndNtp(TimeAdmin *ta)
SetLableFontType(NtpSyncLabel,11,_("Ntp Sync:"));
gtk_grid_attach(GTK_GRID(table) ,NtpSyncLabel, 0 , 1 , 1 , 1);
- NtpSyncSwitch = gtk_switch_new();
+ ta->NtpSyncSwitch = gtk_switch_new();
NtpState = GetNtpState(ta);
if(NtpState)
{
ReloadNtp(ta->proxy,NtpState);
}
ta->NtpState = NtpState;
- gtk_switch_set_state (GTK_SWITCH(NtpSyncSwitch),
+ gtk_switch_set_state (GTK_SWITCH(ta->NtpSyncSwitch),
NtpState);
- gtk_grid_attach(GTK_GRID(table) ,NtpSyncSwitch, 1 , 1 , 1 , 1);
- g_signal_connect (G_OBJECT(NtpSyncSwitch),
+ gtk_grid_attach(GTK_GRID(table) ,ta->NtpSyncSwitch, 1 , 1 , 1 , 1);
+ g_signal_connect (G_OBJECT(ta->NtpSyncSwitch),
"state-set",
G_CALLBACK (ChangeNtpSync),
ta);
@@ -343,7 +374,9 @@ static GtkWidget *SetDate(TimeAdmin *ta)
G_CALLBACK (CloseWindow),
ta);
- ta->SaveButton = gtk_button_new_with_label (_("Save"));
+ gtk_grid_attach(GTK_GRID(table) ,ta->ButtonLock, 1 , 5 , 1 , 1);
+
+ ta->SaveButton = gtk_button_new_with_label (_("Save"));
gtk_widget_set_sensitive(ta->SaveButton,!ta->NtpState);
gtk_grid_attach(GTK_GRID(table) ,ta->SaveButton, 2 , 5 , 1 , 1);
g_signal_connect (ta->SaveButton,
@@ -425,6 +458,7 @@ int main(int argc, char **argv)
exit(0);
}
CreateClockInterface(&ta);
+ UpdatePermission(&ta);
gtk_widget_show_all(ta.MainWindow);
gtk_main();
diff --git a/capplets/time-admin/src/time-share.h b/capplets/time-admin/src/time-share.h
index 453faeee..a0088a87 100644
--- a/capplets/time-admin/src/time-share.h
+++ b/capplets/time-admin/src/time-share.h
@@ -53,6 +53,7 @@ typedef struct
GtkWidget *MinuteSpin;
GtkWidget *SecondSpin;
GtkWidget *TimeZoneButton;
+ GtkWidget *NtpSyncSwitch;
GtkWidget *Calendar;
GtkWidget *CloseButton;
GtkWidget *SaveButton;
@@ -70,6 +71,8 @@ typedef struct
GtkWidget *map;
GtkListStore *CityListStore;
GtkTreeModelSort *CityModelSort;
+ GtkWidget *ButtonLock;
+ GPermission *Permission;
}TimeAdmin;
diff --git a/configure.ac b/configure.ac
index c9561af1..37f208db 100644
--- a/configure.ac
+++ b/configure.ac
@@ -153,6 +153,7 @@ PKG_CHECK_MODULES(MATECC, $COMMON_MODULES libmate-menu >= 1.21.0)
PKG_CHECK_MODULES(MATECC_SHELL, $COMMON_MODULES libmate-menu)
PKG_CHECK_MODULES(DBUS, dbus-1 dbus-glib-1)
+PKG_CHECK_MODULES(POLKIT, polkit-gobject-1)
PKG_CHECK_MODULES(MATE_DESKTOP, mate-desktop-2.0 >= $MATE_DESKTOP_REQUIRED)
PKG_CHECK_MODULES(DEFAULT_APPLICATIONS_CAPPLET, libxml-2.0)
PKG_CHECK_MODULES(MARCO, libmarco-private >= $MARCO_REQUIRED)
@@ -264,8 +265,8 @@ COMMON_LIBS="\$(top_builddir)/capplets/common/libcommon.la"
EXTRA_CFLAGS="-I\$(top_srcdir)/ -DG_LOG_DOMAIN=\"\\\"\$(cappletname)-properties\\\"\""
-MATECC_CAPPLETS_CFLAGS="${COMMON_CFLAGS} ${CAPPLET_CFLAGS} ${EXTRA_CFLAGS} ${DBUS_CFLAGS}"
-MATECC_CAPPLETS_LIBS="${COMMON_LIBS} ${CAPPLET_LIBS} ${DBUS_LIBS}"
+MATECC_CAPPLETS_CFLAGS="${COMMON_CFLAGS} ${CAPPLET_CFLAGS} ${EXTRA_CFLAGS} ${DBUS_CFLAGS} ${POLKIT_CFLAGS}"
+MATECC_CAPPLETS_LIBS="${COMMON_LIBS} ${CAPPLET_LIBS} ${DBUS_LIBS} ${POLKIT_LIBS}"
MATECC_CAPPLETS_CLEANFILES="\$(desktop) \$(desktop).in"
MATECC_CAPPLETS_EXTRA_DIST="ChangeLog \$(desktop).in.in \$(cappletname)-capplet.png \$(pixmaps_DATA)"