diff options
| author | Jan Lipovsky <janlipovsky@gmail.com> | 2010-04-20 15:53:28 +0200 |
|---|---|---|
| committer | Jan Lipovsky <janlipovsky@gmail.com> | 2010-04-20 15:53:28 +0200 |
| commit | 807a346ac1bc467106b7956757fd019833d19b25 (patch) | |
| tree | 7828d1ed091367210918ebdb795ad1ed6541fff1 /sfshare-gui | |
| parent | d324f3f6a85cd1f43deb2ac281eb172abc66f431 (diff) | |
| download | sfshare-807a346ac1bc467106b7956757fd019833d19b25.tar.gz sfshare-807a346ac1bc467106b7956757fd019833d19b25.tar.xz sfshare-807a346ac1bc467106b7956757fd019833d19b25.zip | |
Polkit authorization, nautilus plugin, dbus methods
Diffstat (limited to 'sfshare-gui')
| -rw-r--r-- | sfshare-gui/data/sfs_window.ui | 260 | ||||
| -rw-r--r--[-rwxr-xr-x] | sfshare-gui/src/Makefile | 23 | ||||
| -rw-r--r-- | sfshare-gui/src/dbus_client.c | 297 | ||||
| -rw-r--r-- | sfshare-gui/src/dbus_client.h | 14 | ||||
| -rw-r--r-- | sfshare-gui/src/dbus_client_glue.h | 138 | ||||
| -rw-r--r-- | sfshare-gui/src/sfshare.c | 141 | ||||
| -rw-r--r-- | sfshare-gui/src/sfshare.h | 8 |
7 files changed, 461 insertions, 420 deletions
diff --git a/sfshare-gui/data/sfs_window.ui b/sfshare-gui/data/sfs_window.ui deleted file mode 100644 index 96a1b1b..0000000 --- a/sfshare-gui/data/sfs_window.ui +++ /dev/null @@ -1,260 +0,0 @@ -<?xml version="1.0"?> -<interface> - <requires lib="gtk+" version="2.16"/> - <!-- interface-naming-policy project-wide --> - <object class="GtkWindow" id="sfs_window"> - <property name="width_request">380</property> - <property name="height_request">255</property> - <property name="border_width">6</property> - <property name="title" translatable="yes">Simple File Share</property> - <property name="resizable">False</property> - <property name="icon_name">folder-remote</property> - <child> - <object class="GtkVBox" id="vbox1"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> - <child> - <object class="GtkHBox" id="hbox1"> - <property name="visible">True</property> - <child> - <object class="GtkImage" id="image_icon"> - <property name="visible">True</property> - <property name="pixel_size">60</property> - <property name="icon_name">folder-remote</property> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="heading"> - <property name="width_request">253</property> - <property name="visible">True</property> - <property name="xalign">0.40000000596046448</property> - <property name="label" translatable="yes">Folder Sharing Setup</property> - <property name="single_line_mode">True</property> - <attributes> - <attribute name="weight" value="bold"/> - <attribute name="scale" value="1.500000"/> - </attributes> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkHSeparator" id="hseparator1"> - <property name="visible">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkTable" id="table1"> - <property name="visible">True</property> - <property name="n_rows">4</property> - <property name="n_columns">2</property> - <property name="column_spacing">2</property> - <property name="row_spacing">2</property> - <child> - <object class="GtkLabel" id="share"> - <property name="width_request">95</property> - <property name="visible">True</property> - <property name="xalign">0.10000000149011612</property> - <property name="label" translatable="yes">Share with:</property> - <property name="single_line_mode">True</property> - </object> - <packing> - <property name="x_options"></property> - </packing> - </child> - <child> - <object class="GtkLabel" id="share_name"> - <property name="width_request">95</property> - <property name="visible">True</property> - <property name="xalign">0.10000000149011612</property> - <property name="label" translatable="yes">Share name:</property> - <property name="single_line_mode">True</property> - </object> - <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options"></property> - </packing> - </child> - <child> - <object class="GtkLabel" id="comment"> - <property name="width_request">95</property> - <property name="visible">True</property> - <property name="xalign">0.10000000149011612</property> - <property name="label" translatable="yes">Comment:</property> - <property name="single_line_mode">True</property> - </object> - <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options"></property> - </packing> - </child> - <child> - <object class="GtkEntry" id="entry_share_name"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - </packing> - </child> - <child> - <object class="GtkComboBox" id="combobox_share"> - <property name="visible">True</property> - <property name="model">combo_texts</property> - <property name="active">0</property> - <child> - <object class="GtkCellRendererText" id="combo_cell_texts"/> - <attributes> - <attribute name="markup">0</attribute> - <attribute name="text">0</attribute> - </attributes> - </child> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - </packing> - </child> - <child> - <object class="GtkEntry" id="entry_comment"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox2"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkCheckButton" id="checkbutton_readonly"> - <property name="label" translatable="yes">Read only access</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkCheckButton" id="checkbutton_guestok"> - <property name="label" translatable="yes">Allow GUEST access</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - </packing> - </child> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkHSeparator" id="hseparator2"> - <property name="visible">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="position">3</property> - </packing> - </child> - <child> - <object class="GtkHButtonBox" id="hbuttonbox1"> - <property name="visible">True</property> - <property name="spacing">6</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button_save"> - <property name="label">gtk-save</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button_close"> - <property name="label">gtk-close</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="position">4</property> - </packing> - </child> - </object> - </child> - </object> - <object class="GtkListStore" id="combo_texts"> - <columns> - <!-- column-name share_type --> - <column type="gchararray"/> - </columns> - <data> - <row> - <col id="0" translatable="yes">Do not share this folder</col> - </row> - <row> - <col id="0" translatable="yes">Windows share [Samba]</col> - </row> - </data> - </object> -</interface> diff --git a/sfshare-gui/src/Makefile b/sfshare-gui/src/Makefile index 63d6a7e..2d50ed4 100755..100644 --- a/sfshare-gui/src/Makefile +++ b/sfshare-gui/src/Makefile @@ -1,7 +1,10 @@ # TEMPORARY MAKEFILE CXX=gcc -CXXFLAGS=-std=c99 -Wall `pkg-config --cflags --libs gtk+-2.0 dbus-glib-1` +CXXFLAGS=-std=c99 -Wall `pkg-config --cflags --libs gtk+-2.0 dbus-glib-1 polkit-gtk-1` + +USRDIR=/usr/bin +DATADIR=/usr/share # objektove soubory OBJS= dbus_client.o @@ -10,19 +13,29 @@ all: sfshare ############################################################################### -dbus_client.o: dbus_client.c dbus_client.h +dbus_client.o: dbus_client.c dbus_client.h dbus_client_glue.h $(CXX) $(CXXFLAGS) -c dbus_client.c sfshare: $(OBJS) - $(CXX) $(OBJS) $(CXXFLAGS) sfshare.c -o sfshare + $(CXX) $(OBJS) $(CXXFLAGS) sfshare.c -o sfshare-gui ################################################################################ -.PHONY: clean edit +.PHONY: clean edit uninstall + +install: all + cp sfshare-gui $(USRDIR)/ + mkdir -p $(DATADIR)/sfshare + cp ../data/sfshare_window.ui $(DATADIR)/sfshare/ clean: rm -f *.o - rm -f sfshare + rm -f sfshare-gui + +uninstall: + rm -fr $(DATADIR)/sfshare + rm -f $(USRDIR)/sfshare-gui + ################################################################################ edit: diff --git a/sfshare-gui/src/dbus_client.c b/sfshare-gui/src/dbus_client.c index 24013c3..207d5c0 100644 --- a/sfshare-gui/src/dbus_client.c +++ b/sfshare-gui/src/dbus_client.c @@ -1,177 +1,230 @@ -#include <dbus/dbus-glib.h> #include <glib.h> +#include <gtk/gtk.h> #include <dbus/dbus.h> +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-lowlevel.h> #include <stdio.h> #include <stdlib.h> +#include <polkitgtk/polkitgtk.h> + #include "dbus_client.h" +#include "sfshare.h" +#include "dbus_client_glue.h" -//static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2); -//static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN; -// -//static void -//lose (const char *str, ...) -//{ -// va_list args; -// -// va_start (args, str); -// -// vfprintf (stderr, str, args); -// fputc ('\n', stderr); -// -// va_end (args); -// -// exit (1); -//} -// -//static void -//lose_gerror (const char *prefix, GError *error) -//{ -// lose ("%s: %s", prefix, error->message); -//} -// -//static void -//print_hash_value (gpointer key, gpointer val, gpointer data) -//{ -// printf ("%s -> %s\n", (char *) key, (char *) val); -//} - - -#define SFSHARE_DBUS_NAME "net.lipoja.SimpleFileShare" -#define SFSHARE_DBUS_PATH "/SFShare" -#define SFSHARE_DBUS_INTERFACE "net.lipoja.sfshare" - - -int dbus_sfshare_get_share (const gchar *path, gchar ***result) -{ - DBusGConnection *bus; - DBusGProxy *remote_object; - //DBusGProxy *remote_object_introspectable; - GError *error = NULL; +#define SFSHARE_DBUS_NAME "org.fedoraproject.SimpleFileShare" +#define SFSHARE_DBUS_PATH "/org/fedoraproject/SimpleFileShare" +#define SFSHARE_DBUS_INTERFACE "org.fedoraproject.SimpleFileShare" - g_type_init (); - { - GLogLevelFlags fatal_mask; +/* Dbus */ +DBusGConnection *bus; +DBusGProxy *remote_object; +gboolean is_dbus_connected = FALSE; +gboolean is_authorized = FALSE; - fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); - fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; - g_log_set_always_fatal (fatal_mask); - } +/* Polkit */ +PolkitSubject *subject; +PolkitAuthority *authority; - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (!bus) - g_warning ("Couldn't connect to session bus : %s", error->message); - remote_object = dbus_g_proxy_new_for_name (bus, - SFSHARE_DBUS_NAME, - SFSHARE_DBUS_PATH, - SFSHARE_DBUS_INTERFACE); +/* Connect to DBUS */ +void +dbus_sfshare_connect ( void ) +{ + if(!is_dbus_connected) + { + GError *error = NULL; - if (!dbus_g_proxy_call (remote_object, "GetShareStatus", &error, - G_TYPE_STRING, path, G_TYPE_INVALID, - G_TYPE_STRV, result, G_TYPE_INVALID)) - g_warning ("Failed to complete GetShareStatus: %s", error->message); + bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (!bus) + { + is_dbus_connected = FALSE; + show_message (GTK_MESSAGE_WARNING, "Couldn't connect to session bus: %s", error->message, "%s", "error->message"); + g_warning ("Couldn't connect to session bus : %s", error->message); + return; + } - //printf (result); - g_object_unref (G_OBJECT (remote_object)); + remote_object = dbus_g_proxy_new_for_name (bus, + SFSHARE_DBUS_NAME, + SFSHARE_DBUS_PATH, + SFSHARE_DBUS_INTERFACE); + is_dbus_connected = TRUE; + } +} - return 0; + +/* Disconnect from DBUS */ +void +dbus_sfshare_disconnect ( void ) +{ + if ( is_dbus_connected ) + { + g_object_unref (G_OBJECT (remote_object)); + is_dbus_connected = FALSE; + } } +void +polkit_sfshare_init () +{ + authority = polkit_authority_get (); +} -int -dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok, gchar **result) + +void +polkit_sfshare_free () { - DBusGConnection *bus; - DBusGProxy *remote_object; + g_object_unref (authority); + g_object_unref (subject); +} - //DBusGProxy *remote_object_introspectable; - GError *error = NULL; - g_type_init (); +static void +check_authorization_cb (PolkitAuthority *authority, + GAsyncResult *res, + gpointer *data) +{ + GError *error; + PolkitAuthorizationResult *result; - { - GLogLevelFlags fatal_mask; + is_authorized = FALSE; - fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); - fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; - g_log_set_always_fatal (fatal_mask); + error = NULL; + result = polkit_authority_check_authorization_finish (authority, res, &error); + if (error != NULL) + { + g_print ("Error checking authorization: %s\n", error->message); + g_error_free (error); } + else + { + if (polkit_authorization_result_get_is_authorized (result)) + { + is_authorized = TRUE; + save_share_button (); + } + else if (polkit_authorization_result_get_is_challenge (result)) + { + is_authorized = FALSE; + } + else + { + is_authorized = FALSE; + } + } +} - gchar **share; - share = g_new (gchar *, 6); - - share[0] = g_strdup (name); - share[1] = g_strdup (path); - share[2] = g_strdup (comment); - share[3] = g_strdup (read_only); - share[4] = g_strdup (guest_ok); - share[5] = NULL; +void +polkit_sfshare_check (const gchar *action_id) +{ + subject = polkit_system_bus_name_new (dbus_bus_get_unique_name (dbus_g_connection_get_connection (bus))); - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (!bus) - g_warning ("Couldn't connect to session bus : %s", error->message); + polkit_authority_check_authorization (authority, + subject, + action_id, + NULL, /* PolkitDetails */ + POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, + NULL, + (GAsyncReadyCallback) check_authorization_cb, + NULL); +} - remote_object = dbus_g_proxy_new_for_name (bus, - SFSHARE_DBUS_NAME, - SFSHARE_DBUS_PATH, - SFSHARE_DBUS_INTERFACE); - if (!dbus_g_proxy_call (remote_object, "SetupShare", &error, - G_TYPE_STRV, share, G_TYPE_INVALID, - G_TYPE_STRING, result, G_TYPE_INVALID)) - g_warning ("Failed to complete SetupShare: %s", error->message); +int +dbus_sfshare_get_share (const gchar *path, gchar ***result) +{ + GError *error = NULL; + dbus_sfshare_connect (); + if (!org_fedoraproject_SimpleFileShare_get_share_status (remote_object, path, result, &error)) + { + show_message (GTK_MESSAGE_WARNING, "%s", "Warning!", "Remote method get_share_status failed: %s", error->message); + g_warning ("Remote method get_share_status failed: %s", error->message); + g_error_free (error); - //printf (result); - g_strfreev(share); + return -1; + } return 0; } +/* Reply of setup_share */ +void +set_share_reply (DBusGProxy *proxy, GError *error, gpointer userdata) +{ + if (error!= NULL) + { + show_message (GTK_MESSAGE_WARNING, "%s","Warning!", "An error occured while calling setup_share remote method: %s", error->message); + g_warning ("An error occured while calling setup_share remote method: %s", error->message); + g_error_free (error); + return; + } -int -dbus_sfshare_delete_share (const gchar *path, gchar **result) + reload_share_info (); + show_message (GTK_MESSAGE_INFO, "%s" ,"Folder is now shared!", "%s", "Share section was succesfully writed to smb.conf"); +} + + + +void +dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok) { - DBusGConnection *bus; - DBusGProxy *remote_object; GError *error = NULL; - g_type_init (); + const gchar *share[6] = {name, path, comment, read_only, guest_ok, NULL}; - { - GLogLevelFlags fatal_mask; + dbus_sfshare_connect (); - fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); - fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; - g_log_set_always_fatal (fatal_mask); + /* Async call of setup_share metod */ + if (!org_fedoraproject_SimpleFileShare_setup_share_async (remote_object, share, set_share_reply, NULL)) + { + show_message (GTK_MESSAGE_WARNING, "%s", "Warning!", "Remote method setup_share failed: %s", error->message); + g_warning ("Remote method setup_share failed: %s", error->message); + g_error_free (error); + return; } +} - bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (!bus) - g_warning ("Couldn't connect to session bus : %s", error->message); - remote_object = dbus_g_proxy_new_for_name (bus, - SFSHARE_DBUS_NAME, - SFSHARE_DBUS_PATH, - SFSHARE_DBUS_INTERFACE); +void +delete_share_reply (DBusGProxy *proxy, GError *error, gpointer userdata) +{ + if (error!= NULL) + { + show_message (GTK_MESSAGE_WARNING, "%s","Warning!", "An error occured while calling delete_share remote method: %s", error->message); + g_warning ("An error occured while calling delete_share remote method: %s", error->message); + g_error_free (error); + return; + } - if (!dbus_g_proxy_call (remote_object, "DeleteShare", &error, - G_TYPE_STRING, path, G_TYPE_INVALID, - G_TYPE_STRING, result, G_TYPE_INVALID)) - g_warning ("Failed to complete DeleteShare: %s", error->message); + reload_share_info (); - //printf (result); - g_object_unref (G_OBJECT (remote_object)); + show_message (GTK_MESSAGE_INFO, "%s", "Share was deleted!", "%s", "Share section was succesfully deleted from smb.conf"); +} - return 0; + +void +dbus_sfshare_delete_share (const gchar *path) +{ + GError *error = NULL; + + dbus_sfshare_connect (); + + /* Async call of delete_share metod */ + if (!org_fedoraproject_SimpleFileShare_delete_share_async (remote_object, path, delete_share_reply, NULL)) + { + show_message (GTK_MESSAGE_WARNING, "%s", "Warning!", "Remote method delete_share failed: %s", error->message); + g_warning ("Remote method delete_share failed: %s", error->message); + g_error_free (error); + return; + } } diff --git a/sfshare-gui/src/dbus_client.h b/sfshare-gui/src/dbus_client.h index 1a14bbd..e711ebe 100644 --- a/sfshare-gui/src/dbus_client.h +++ b/sfshare-gui/src/dbus_client.h @@ -2,8 +2,18 @@ #define DBUS_SERVICE_H int dbus_sfshare_get_share (const gchar *path, gchar ***result); -int dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok, gchar **result); -int dbus_sfshare_delete_share (const gchar *path, gchar **result); +void dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok); +void dbus_sfshare_delete_share (const gchar *path); +void dbus_sfshare_connect ( void ); +void dbus_sfshare_disconnect ( void ); + + +#define ACTION_ID_SETUP_SHARE "org.fedoraproject.SimpleFileShare.setup_share" +#define ASTION_ID_DELETE_SHARE "org.fedoraproject.SimpleFileShare.delete_share" + +void polkit_sfshare_check (const gchar *action_id); +void polkit_sfshare_init(); + #endif diff --git a/sfshare-gui/src/dbus_client_glue.h b/sfshare-gui/src/dbus_client_glue.h new file mode 100644 index 0000000..a494714 --- /dev/null +++ b/sfshare-gui/src/dbus_client_glue.h @@ -0,0 +1,138 @@ +/* Generated by dbus-binding-tool; do not edit! */ + +#include <glib.h> +#include <dbus/dbus-glib.h> + +G_BEGIN_DECLS + +#ifndef _DBUS_GLIB_ASYNC_DATA_FREE +#define _DBUS_GLIB_ASYNC_DATA_FREE +static +#ifdef G_HAVE_INLINE +inline +#endif +void +_dbus_glib_async_data_free (gpointer stuff) +{ + g_slice_free (DBusGAsyncData, stuff); +} +#endif + +#ifndef DBUS_GLIB_CLIENT_WRAPPERS_org_fedoraproject_SimpleFileShare +#define DBUS_GLIB_CLIENT_WRAPPERS_org_fedoraproject_SimpleFileShare + +static +#ifdef G_HAVE_INLINE +inline +#endif +gboolean +org_fedoraproject_SimpleFileShare_get_share_status (DBusGProxy *proxy, const char * IN_path, char *** OUT_status, GError **error) + +{ + return dbus_g_proxy_call (proxy, "get_share_status", error, G_TYPE_STRING, IN_path, G_TYPE_INVALID, G_TYPE_STRV, OUT_status, G_TYPE_INVALID); +} + +typedef void (*org_fedoraproject_SimpleFileShare_get_share_status_reply) (DBusGProxy *proxy, char * *OUT_status, GError *error, gpointer userdata); + +static void +org_fedoraproject_SimpleFileShare_get_share_status_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +{ + DBusGAsyncData *data = (DBusGAsyncData*) user_data; + GError *error = NULL; + char ** OUT_status; + dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRV, &OUT_status, G_TYPE_INVALID); + (*(org_fedoraproject_SimpleFileShare_get_share_status_reply)data->cb) (proxy, OUT_status, error, data->userdata); + return; +} + +static +#ifdef G_HAVE_INLINE +inline +#endif +DBusGProxyCall* +org_fedoraproject_SimpleFileShare_get_share_status_async (DBusGProxy *proxy, const char * IN_path, org_fedoraproject_SimpleFileShare_get_share_status_reply callback, gpointer userdata) + +{ + DBusGAsyncData *stuff; + stuff = g_slice_new (DBusGAsyncData); + stuff->cb = G_CALLBACK (callback); + stuff->userdata = userdata; + return dbus_g_proxy_begin_call (proxy, "get_share_status", org_fedoraproject_SimpleFileShare_get_share_status_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_STRING, IN_path, G_TYPE_INVALID); +} +static +#ifdef G_HAVE_INLINE +inline +#endif +gboolean +org_fedoraproject_SimpleFileShare_setup_share (DBusGProxy *proxy, const char ** IN_parameters, GError **error) + +{ + return dbus_g_proxy_call (proxy, "setup_share", error, G_TYPE_STRV, IN_parameters, G_TYPE_INVALID, G_TYPE_INVALID); +} + +typedef void (*org_fedoraproject_SimpleFileShare_setup_share_reply) (DBusGProxy *proxy, GError *error, gpointer userdata); + +static void +org_fedoraproject_SimpleFileShare_setup_share_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +{ + DBusGAsyncData *data = (DBusGAsyncData*) user_data; + GError *error = NULL; + dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); + (*(org_fedoraproject_SimpleFileShare_setup_share_reply)data->cb) (proxy, error, data->userdata); + return; +} + +static +#ifdef G_HAVE_INLINE +inline +#endif +DBusGProxyCall* +org_fedoraproject_SimpleFileShare_setup_share_async (DBusGProxy *proxy, const char ** IN_parameters, org_fedoraproject_SimpleFileShare_setup_share_reply callback, gpointer userdata) + +{ + DBusGAsyncData *stuff; + stuff = g_slice_new (DBusGAsyncData); + stuff->cb = G_CALLBACK (callback); + stuff->userdata = userdata; + return dbus_g_proxy_begin_call (proxy, "setup_share", org_fedoraproject_SimpleFileShare_setup_share_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_STRV, IN_parameters, G_TYPE_INVALID); +} +static +#ifdef G_HAVE_INLINE +inline +#endif +gboolean +org_fedoraproject_SimpleFileShare_delete_share (DBusGProxy *proxy, const char * IN_path, GError **error) + +{ + return dbus_g_proxy_call (proxy, "delete_share", error, G_TYPE_STRING, IN_path, G_TYPE_INVALID, G_TYPE_INVALID); +} + +typedef void (*org_fedoraproject_SimpleFileShare_delete_share_reply) (DBusGProxy *proxy, GError *error, gpointer userdata); + +static void +org_fedoraproject_SimpleFileShare_delete_share_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) +{ + DBusGAsyncData *data = (DBusGAsyncData*) user_data; + GError *error = NULL; + dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID); + (*(org_fedoraproject_SimpleFileShare_delete_share_reply)data->cb) (proxy, error, data->userdata); + return; +} + +static +#ifdef G_HAVE_INLINE +inline +#endif +DBusGProxyCall* +org_fedoraproject_SimpleFileShare_delete_share_async (DBusGProxy *proxy, const char * IN_path, org_fedoraproject_SimpleFileShare_delete_share_reply callback, gpointer userdata) + +{ + DBusGAsyncData *stuff; + stuff = g_slice_new (DBusGAsyncData); + stuff->cb = G_CALLBACK (callback); + stuff->userdata = userdata; + return dbus_g_proxy_begin_call (proxy, "delete_share", org_fedoraproject_SimpleFileShare_delete_share_async_callback, stuff, _dbus_glib_async_data_free, G_TYPE_STRING, IN_path, G_TYPE_INVALID); +} +#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_org_fedoraproject_SimpleFileShare */ + +G_END_DECLS diff --git a/sfshare-gui/src/sfshare.c b/sfshare-gui/src/sfshare.c index 7357361..85e71a1 100644 --- a/sfshare-gui/src/sfshare.c +++ b/sfshare-gui/src/sfshare.c @@ -6,6 +6,7 @@ #include <stdio.h> #include <stdlib.h> + /* Types of share service */ typedef enum share_service { @@ -15,8 +16,11 @@ typedef enum share_service } TShare_service; +/* Dialog widgets */ typedef struct _sfsdialog { + GtkWidget *window; + GtkWidget *gui_close; GtkWidget *gui_about; @@ -37,9 +41,35 @@ SFSDialog sfsdialog; /* Is directory shared? */ gboolean shared_smbconf = FALSE; +/* path to folder */ gchar *dir_path; +/* Show info, error or warning message*/ +void +show_message (GtkMessageType type, const gchar *format, gchar *msgtxt, const gchar *format_sec, gchar *msgtxt_sec) +{ + GtkWidget *msg_widget; + + msg_widget = gtk_message_dialog_new ( GTK_WINDOW (sfsdialog.window), + GTK_DIALOG_MODAL, + type, + GTK_BUTTONS_OK, + format, + msgtxt); + + gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG (msg_widget), + format_sec, + msgtxt_sec); + + g_signal_connect_swapped ( msg_widget, + "response", + G_CALLBACK (gtk_widget_destroy), + msg_widget); + + gtk_widget_show (msg_widget); +} + /* * Fill in information about shared directory to GUI */ @@ -54,11 +84,21 @@ load_share_info (gchar *path) gboolean guestok = FALSE; TShare_service share_type = DO_NOT_SHARE; + shared_smbconf = FALSE; + if (!dbus_sfshare_get_share (path, &share)) { /* Folder is not shared */ if(share[0] == NULL) { + /* Directory is not shared - clear info */ + gtk_entry_set_text( GTK_ENTRY (sfsdialog.gui_sharename), ""); + gtk_entry_set_text( GTK_ENTRY (sfsdialog.gui_comment), ""); + gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_readonly), FALSE); + gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_guestok), FALSE); + gtk_combo_box_set_active (GTK_COMBO_BOX (sfsdialog.gui_share), DO_NOT_SHARE); + + /* Free */ g_strfreev(share); return; } @@ -85,32 +125,64 @@ load_share_info (gchar *path) } } -/* -* Call SetShare -*/ -void save_share ( void ) +void +reload_share_info ( void ) { + /* Reload info */ + load_share_info(dir_path); +} +void +sfshare_authority_check ( void ) +{ gboolean shared_gui = FALSE; - if ((gtk_combo_box_get_active (GTK_COMBO_BOX (sfsdialog.gui_share)) != DO_NOT_SHARE) ) shared_gui = TRUE; + /* If not shared in smbconf and user do not want to share it nothing changes */ if (!shared_gui && !shared_smbconf) return; + /* user want to delete share from smb.conf*/ + if (!shared_gui && shared_smbconf) + { + polkit_sfshare_check (ASTION_ID_DELETE_SHARE); + + return; + } /* user want to write share to smb.conf*/ - if (!shared_gui) + if (shared_gui) { - gchar *result; - if (!dbus_sfshare_delete_share(dir_path ,&result)) - { - g_free(result); - } + polkit_sfshare_check (ACTION_ID_SETUP_SHARE); + } +} + + +/* +* Call set_share +*/ +void +save_share_button ( void ) +{ + + gboolean shared_gui = FALSE; + + if ((gtk_combo_box_get_active (GTK_COMBO_BOX (sfsdialog.gui_share)) != DO_NOT_SHARE) ) + shared_gui = TRUE; + + /* If not shared in smbconf and user do not want to share it nothing changes */ + if (!shared_gui && !shared_smbconf) + return; + + + /* user want to delete share from smb.conf*/ + if (!shared_gui && shared_smbconf) + { + dbus_sfshare_delete_share(dir_path); return; } @@ -123,8 +195,6 @@ void save_share ( void ) const gchar *ronly; const gchar *gok; - gchar *result; - const gchar *share_name = gtk_entry_get_text ( GTK_ENTRY (sfsdialog.gui_sharename)); const gchar *comment = gtk_entry_get_text ( GTK_ENTRY (sfsdialog.gui_comment)); @@ -138,48 +208,50 @@ void save_share ( void ) else gok = no; - if (!dbus_sfshare_set_share (share_name, dir_path, comment, ronly, gok, &result)) - { - /* Free */ - g_free(result); - } - + /* Call dbus method */ + dbus_sfshare_set_share (share_name, dir_path, comment, ronly, gok); return; } - } -int main( int argc, char **argv ) +int +main ( int argc, char **argv ) { + GtkBuilder *builder; - GtkWidget *window; + gchar *filename; if (argc < 2) { - g_warning ("Bad parameter!"); + g_warning ("Wrong parameter!"); exit(1); } + dir_path = argv[1]; gtk_init( &argc, &argv ); /* Create builder and load interface */ builder = gtk_builder_new(); - gtk_builder_add_from_file( builder, "../data/sfs_window.ui", NULL ); + + filename = "/usr/share/sfshare/sfshare_window.ui"; + if (!g_file_test (filename, G_FILE_TEST_EXISTS)) + filename = "../data/sfshare_window.ui"; + + gtk_builder_add_from_file( builder, filename, NULL ); /* Obtain widgets that we need */ - window = GTK_WIDGET( gtk_builder_get_object( builder, "sfs_window" ) ); + sfsdialog.window = GTK_WIDGET ( gtk_builder_get_object( builder, "sfshare_window" )); - g_signal_connect (window, "destroy", gtk_main_quit, NULL); + g_signal_connect (sfsdialog.window, "destroy", gtk_main_quit, NULL); sfsdialog.gui_close = GTK_WIDGET( gtk_builder_get_object( builder, "button_close" )); - g_signal_connect (sfsdialog.gui_close, "clicked", gtk_main_quit, GTK_OBJECT (window)); //data.about = GTK_WIDGET( gtk_builder_get_object( builder, "aboutdialog1" ) ); - + g_signal_connect (sfsdialog.gui_close, "clicked", gtk_main_quit, GTK_OBJECT (sfsdialog.window)); sfsdialog.gui_close = GTK_WIDGET( gtk_builder_get_object( builder, "button_save" )); - g_signal_connect (sfsdialog.gui_close, "clicked", G_CALLBACK (save_share), NULL); + g_signal_connect (sfsdialog.gui_close, "clicked", G_CALLBACK (sfshare_authority_check), NULL); /* Share info items */ sfsdialog.gui_share = GTK_WIDGET( gtk_builder_get_object( builder, "combobox_share")); @@ -196,11 +268,18 @@ int main( int argc, char **argv ) g_object_unref (G_OBJECT( builder )); /* Load info about directory */ - load_share_info (argv[1]); + load_share_info (dir_path); /* Show main window and start main loop */ - gtk_widget_show( window ); + gtk_widget_show ( sfsdialog.window ); + + /* Dbus and polkit init */ + dbus_sfshare_connect (); + polkit_sfshare_init(); + gtk_main(); + dbus_sfshare_disconnect (); + return(0); } diff --git a/sfshare-gui/src/sfshare.h b/sfshare-gui/src/sfshare.h new file mode 100644 index 0000000..cb40078 --- /dev/null +++ b/sfshare-gui/src/sfshare.h @@ -0,0 +1,8 @@ +#ifndef SFSHARE_H +#define SFSHARE_H + +void show_message (GtkMessageType type, const gchar *format, gchar *msgtxt, const gchar *format_sec, gchar *msgtxt_sec); +void save_share_button ( void ); +void reload_share_info ( void ); +#endif + |
