From ba2bbc75e63b968d03da1094fcb8f28a1f734b39 Mon Sep 17 00:00:00 2001 From: Jan Lipovsky Date: Fri, 28 May 2010 13:59:28 +0200 Subject: Release --- sfshare-gui/Makefile.am | 37 +++- sfshare-gui/data/Makefile.am | 7 +- sfshare-gui/data/sfshare_window.ui | 0 sfshare-gui/dbus_client.c | 254 +++++++++++++++++++++++++ sfshare-gui/dbus_client.h | 48 +++++ sfshare-gui/dbus_client_glue.h | 138 ++++++++++++++ sfshare-gui/sfshare.c | 366 +++++++++++++++++++++++++++++++++++++ sfshare-gui/sfshare.h | 34 ++++ sfshare-gui/src/Makefile.am | 11 -- sfshare-gui/src/dbus_client.c | 251 ------------------------- sfshare-gui/src/dbus_client.h | 45 ----- sfshare-gui/src/dbus_client_glue.h | 138 -------------- sfshare-gui/src/sfshare.c | 357 ------------------------------------ sfshare-gui/src/sfshare.h | 31 ---- 14 files changed, 875 insertions(+), 842 deletions(-) mode change 100644 => 100755 sfshare-gui/data/sfshare_window.ui create mode 100755 sfshare-gui/dbus_client.c create mode 100755 sfshare-gui/dbus_client.h create mode 100755 sfshare-gui/dbus_client_glue.h create mode 100755 sfshare-gui/sfshare.c create mode 100755 sfshare-gui/sfshare.h delete mode 100755 sfshare-gui/src/Makefile.am delete mode 100644 sfshare-gui/src/dbus_client.c delete mode 100644 sfshare-gui/src/dbus_client.h delete mode 100644 sfshare-gui/src/dbus_client_glue.h delete mode 100644 sfshare-gui/src/sfshare.c delete mode 100644 sfshare-gui/src/sfshare.h (limited to 'sfshare-gui') diff --git a/sfshare-gui/Makefile.am b/sfshare-gui/Makefile.am index 3310172..04aaa75 100755 --- a/sfshare-gui/Makefile.am +++ b/sfshare-gui/Makefile.am @@ -1,5 +1,34 @@ -AUTOMAKE_OPTIONS = foreign +NULL = -SUBDIRS = \ - src \ - data +SUBDIRS = data + +INCLUDES = \ + -DDATADIR=\"$(datadir)\" \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ + $(POLKIT_CFLAGS) \ + $(NULL) + +LDADD = \ + $(GLIB_LIBS) \ + $(GTK_LIBS) \ + $(DBUS_GLIB_LIBS) \ + $(POLKIT_LIBS) \ + $(NULL) + + +bin_PROGRAMS = sfshare-gui + +sfshare_gui_SOURCES = \ + dbus_client.h \ + dbus_client.c \ + dbus_client_glue.h \ + sfshare.h \ + sfshare.c \ + $(NULL) diff --git a/sfshare-gui/data/Makefile.am b/sfshare-gui/data/Makefile.am index 41a66d3..5a50cfe 100755 --- a/sfshare-gui/data/Makefile.am +++ b/sfshare-gui/data/Makefile.am @@ -1,7 +1,4 @@ -# TODO $(sysconfdir)/sfshare/ -uidir = /usr/share/sfshare/ +uidir = $(datadir)/sfshare/ ui_DATA = sfshare_window.ui - - -EXTRA_DIST = $(ui_DATA) +EXTRA_DIST = $(ui_DATA) diff --git a/sfshare-gui/data/sfshare_window.ui b/sfshare-gui/data/sfshare_window.ui old mode 100644 new mode 100755 diff --git a/sfshare-gui/dbus_client.c b/sfshare-gui/dbus_client.c new file mode 100755 index 0000000..87a0e69 --- /dev/null +++ b/sfshare-gui/dbus_client.c @@ -0,0 +1,254 @@ +/* + * dbus_client.c + * + * 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 library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Jan Lipovsky + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "dbus_client.h" +#include "sfshare.h" +#include "dbus_client_glue.h" + +#define SFSHARE_DBUS_NAME "org.fedoraproject.SimpleFileShare" +#define SFSHARE_DBUS_PATH "/org/fedoraproject/SimpleFileShare" +#define SFSHARE_DBUS_INTERFACE "org.fedoraproject.SimpleFileShare" + +/* Dbus */ +DBusGConnection *bus; +DBusGProxy *remote_object; +gboolean is_dbus_connected = FALSE; +gboolean is_authorized = FALSE; + +/* Polkit */ +PolkitSubject *subject; +PolkitAuthority *authority; + + +/** Connect to DBUS */ +void +dbus_sfshare_connect ( void ) +{ + if(!is_dbus_connected) + { + GError *error = NULL; + + 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); + + g_error_free (error); + return; + } + + remote_object = dbus_g_proxy_new_for_name (bus, + SFSHARE_DBUS_NAME, + SFSHARE_DBUS_PATH, + SFSHARE_DBUS_INTERFACE); + + is_dbus_connected = TRUE; + } +} + + +/** Disconnect from DBUS - free object */ +void +dbus_sfshare_disconnect ( void ) +{ + if ( is_dbus_connected ) + { + g_object_unref (G_OBJECT (remote_object)); + is_dbus_connected = FALSE; + } +} + +/** Get Polkit Authority */ +void +polkit_sfshare_init () +{ + authority = polkit_authority_get (); +} + +/** Free Polkit objects */ +void +polkit_sfshare_free () +{ + g_object_unref (authority); + g_object_unref (subject); +} + +/** PolicyKit callback */ +static void +check_authorization_cb (PolkitAuthority *authority, + GAsyncResult *res, + gpointer *data) +{ + GError *error; + PolkitAuthorizationResult *result; + + is_authorized = FALSE; + + 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 (); + } + else if (polkit_authorization_result_get_is_challenge (result)) + { + is_authorized = FALSE; + } + else + { + is_authorized = FALSE; + } + } +} + +/** Check privileges vie PolicyKit */ +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))); + + polkit_authority_check_authorization (authority, + subject, + action_id, + NULL, /* PolkitDetails */ + POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, + NULL, + (GAsyncReadyCallback) check_authorization_cb, + NULL); +} + +/** Call daemon D-Bus methot get_share_status */ +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); + + 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; + } + + reload_share_info (); + show_message (GTK_MESSAGE_INFO, "%s" ,"Folder is now shared!", "%s", "Share section was succesfully writed to smb.conf"); +} + + +/** Async call daemon D-Bus methot setup_share */ +void +dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok) +{ + GError *error = NULL; + + const gchar *share[6] = {name, path, comment, read_only, guest_ok, NULL}; + + dbus_sfshare_connect (); + + /* 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; + } +} + + + +/** Reply of delete_share */ +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; + } + + reload_share_info (); + + show_message (GTK_MESSAGE_INFO, "%s", "Share was deleted!", "%s", "Share section was succesfully deleted from smb.conf"); +} + + +/** Async call daemon D-Bus methot delete_share */ +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/dbus_client.h b/sfshare-gui/dbus_client.h new file mode 100755 index 0000000..9a81ee8 --- /dev/null +++ b/sfshare-gui/dbus_client.h @@ -0,0 +1,48 @@ +/* + * dbus_client.c + * + * 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 library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Jan Lipovsky + */ + +#ifndef DBUS_SERVICE_H +#define DBUS_SERVICE_H + +/** Call daemon D-Bus methot get_share_status */ +int dbus_sfshare_get_share (const gchar *path, gchar ***result); +/** Async call daemon D-Bus methot setup_share */ +void dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok); +/** Async call daemon D-Bus methot delete_share */ +void dbus_sfshare_delete_share (const gchar *path); +/** Connect to DBUS */ +void dbus_sfshare_connect ( void ); +/** Disconnect from DBUS - free object */ +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" + +/** Check privileges vie PolicyKit */ +void polkit_sfshare_check (const gchar *action_id); +/** Get Polkit Authority */ +void polkit_sfshare_init(); +/** Free Polkit objects */ +void polkit_sfshare_free(); + + +#endif + diff --git a/sfshare-gui/dbus_client_glue.h b/sfshare-gui/dbus_client_glue.h new file mode 100755 index 0000000..a494714 --- /dev/null +++ b/sfshare-gui/dbus_client_glue.h @@ -0,0 +1,138 @@ +/* Generated by dbus-binding-tool; do not edit! */ + +#include +#include + +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/sfshare.c b/sfshare-gui/sfshare.c new file mode 100755 index 0000000..fe2f3e2 --- /dev/null +++ b/sfshare-gui/sfshare.c @@ -0,0 +1,366 @@ +/* + * sfshare.c + * + * 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 library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Jan Lipovsky + */ + +#include +#include /* strlen */ + +#include "dbus_client.h" +#include + +#include +#include + + +/** Types of share service */ +typedef enum share_service +{ + NOTHING_SELECTED = -1, + DO_NOT_SHARE, + WIDNOWS_SHARE_SAMBA +} TShare_service; + + +/** Dialog widgets */ +typedef struct _sfsdialog +{ + GtkWidget *window; + + GtkWidget *gui_close; + GtkWidget *gui_save; + + /* Share informations */ + GtkWidget *gui_share; + GtkWidget *gui_sharename; + GtkWidget *gui_comment; + GtkWidget *gui_readonly; + GtkWidget *gui_guestok; + + +} SFSDialog; + +/** Dialog window */ +SFSDialog sfsdialog; + +/** Is directory shared? */ +gboolean shared_smbconf = FALSE; + +/** Did user changed something? */ +gboolean change_in_gui = FALSE; + +/** Path to folder */ +gchar *dir_path; + + +void +sfshare_dialog_destroy () +{ + gtk_widget_destroy (sfsdialog.gui_guestok); + gtk_widget_destroy (sfsdialog.gui_readonly); + gtk_widget_destroy (sfsdialog.gui_comment); + gtk_widget_destroy (sfsdialog.gui_sharename); + gtk_widget_destroy (sfsdialog.gui_share); + gtk_widget_destroy (sfsdialog.gui_save); + gtk_widget_destroy (sfsdialog.gui_close); + gtk_widget_destroy (sfsdialog.window); +} + + +/** On change event - enable Save button */ +void +gui_changed ( void ) +{ + if (!change_in_gui) + { + /* Enale save button */ + gtk_widget_set_sensitive (sfsdialog.gui_save, TRUE); + change_in_gui = TRUE; + } +} + + +/** Show info, error or warning message */ +void +show_message (GtkMessageType type, const gchar *format, gchar *msgtxt, const gchar *format_sec, gchar *msgtxt_sec) +{ + GtkWidget *dialog; + + dialog = gtk_message_dialog_new ( GTK_WINDOW (sfsdialog.window), + GTK_DIALOG_DESTROY_WITH_PARENT, + type, + GTK_BUTTONS_OK, + format, + msgtxt); + + gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG (dialog), + format_sec, + msgtxt_sec); + + gtk_dialog_run ( GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); +} + + +/** +* Fill in information about shared directory to GUI +*/ +void +load_share_info ( void ) +{ + + /* [share name], "path =", "commennt =", "read only =", "writable =", "guest ok =" */ + + gchar **share; + gboolean readonly = FALSE; + gboolean guestok = FALSE; + TShare_service share_type = DO_NOT_SHARE; + + shared_smbconf = FALSE; + change_in_gui = FALSE; + + /* Disable save button */ + gtk_widget_set_sensitive (sfsdialog.gui_save, FALSE); + + if (!dbus_sfshare_get_share (dir_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; + } + + share_type = WIDNOWS_SHARE_SAMBA; + + if (!g_strcmp0(share[3], "yes")) + readonly = TRUE; + + if (!g_strcmp0(share[4], "yes")) + guestok = TRUE; + + /* Fill in information about shared directory to GUI */ + gtk_entry_set_text( GTK_ENTRY (sfsdialog.gui_sharename), share[0]); + gtk_entry_set_text( GTK_ENTRY (sfsdialog.gui_comment), share[2]); + gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_readonly), readonly); + gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_guestok), guestok); + gtk_combo_box_set_active (GTK_COMBO_BOX (sfsdialog.gui_share), share_type); + + shared_smbconf = TRUE; + + /* Free vector*/ + g_strfreev(share); + } +} + +void +reload_share_info ( void ) +{ + /* Reload info */ + load_share_info (); +} + +/** +* Check authority via PolicyKit - OnClick Save +*/ +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) + { + const gchar *share_name = gtk_entry_get_text ( GTK_ENTRY (sfsdialog.gui_sharename)); + if (!g_strcmp0(share_name, (""))) + { + show_message(GTK_MESSAGE_WARNING,"%s","Warning!","%s","Share name must be set!"); + return; + } + + polkit_sfshare_check (ACTION_ID_SETUP_SHARE); + } +} + + + +/** +* Save button - call functions to save/change or delete section +*/ +void +save_share ( 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; + } + + /* user want to write share to smb.conf*/ + if (shared_gui) + { + const gchar *yes = "yes"; + const gchar *no = "no"; + + const gchar *ronly; + const gchar *gok; + + 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)); + + if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_readonly))) + ronly = yes; + else + ronly = no; + + if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_guestok))) + gok = yes; + else + gok = no; + + /* Call dbus method */ + dbus_sfshare_set_share (share_name, dir_path, comment, ronly, gok); + return; + } +} + +/** +* Create main window +*/ +int +main ( int argc, char **argv ) +{ + + GtkBuilder *builder; + const gchar *ui_filename; + GError *error = NULL; + + if (argc < 2) + { + g_warning ("Wrong parameter!"); + exit(1); + } + /* First parameter is path to shared folder */ + dir_path = argv[1]; + + gtk_init( &argc, &argv ); + + if (!g_file_test (dir_path, G_FILE_TEST_IS_DIR)) + { + g_warning ("Directory \'%s\' does not exist!", dir_path); + exit(1); + } + + + /* Create builder and load interface */ + builder = gtk_builder_new (); + + ui_filename = DATADIR "/sfshare/sfshare_window.ui"; + if (!g_file_test (ui_filename, G_FILE_TEST_EXISTS)) + ui_filename = "data/sfshare_window.ui"; + + + if (!gtk_builder_add_from_file ( builder, ui_filename, &error )) + { + g_warning ("gtk_builder_add_from_file failed: %s", error->message); + g_error_free (error); + return -1; + } + + /* Obtain widgets that we need */ + sfsdialog.window = GTK_WIDGET ( gtk_builder_get_object( builder, "sfshare_window" )); + 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 (sfsdialog.window)); + + sfsdialog.gui_save = GTK_WIDGET( gtk_builder_get_object( builder, "button_save" )); + g_signal_connect (sfsdialog.gui_save, "clicked", G_CALLBACK (sfshare_authority_check), NULL); + + /* Share info items */ + sfsdialog.gui_share = GTK_WIDGET( gtk_builder_get_object( builder, "combobox_share")); + sfsdialog.gui_sharename = GTK_WIDGET( gtk_builder_get_object( builder, "entry_share_name")); + sfsdialog.gui_comment = GTK_WIDGET( gtk_builder_get_object( builder, "entry_comment")); + sfsdialog.gui_readonly = GTK_WIDGET( gtk_builder_get_object( builder, "checkbutton_readonly")); + sfsdialog.gui_guestok = GTK_WIDGET( gtk_builder_get_object( builder, "checkbutton_guestok")); + + + g_signal_connect (sfsdialog.gui_share, "changed", G_CALLBACK (gui_changed), NULL); + g_signal_connect (sfsdialog.gui_sharename, "changed", G_CALLBACK (gui_changed), NULL); + g_signal_connect (sfsdialog.gui_comment, "changed", G_CALLBACK (gui_changed), NULL); + g_signal_connect (sfsdialog.gui_readonly, "clicked", G_CALLBACK (gui_changed), NULL); + g_signal_connect (sfsdialog.gui_guestok, "clicked", G_CALLBACK (gui_changed), NULL); + + + /* Destroy builder */ + g_object_unref (G_OBJECT( builder )); + + /* Load info about directory */ + load_share_info (); + + /* Show main window and start main loop */ + gtk_widget_show ( sfsdialog.window ); + + /* Dbus and polkit init */ + dbus_sfshare_connect (); + polkit_sfshare_init(); + + gtk_main (); + + dbus_sfshare_disconnect (); + polkit_sfshare_free (); + + return(0); +} diff --git a/sfshare-gui/sfshare.h b/sfshare-gui/sfshare.h new file mode 100755 index 0000000..a5c76a3 --- /dev/null +++ b/sfshare-gui/sfshare.h @@ -0,0 +1,34 @@ +/* + * sfshare.h + * + * 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 library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Jan Lipovsky + */ + +#ifndef SFSHARE_H +#define SFSHARE_H + +/** Shows error, info, warning dialog */ +void show_message (GtkMessageType type, const gchar *format, gchar *msgtxt, const gchar *format_sec, gchar *msgtxt_sec); + +/** Call functions to save/change or delete section */ +void save_share ( void ); + +/** Reload smbd and nmbd */ +void reload_share_info ( void ); + +#endif + diff --git a/sfshare-gui/src/Makefile.am b/sfshare-gui/src/Makefile.am deleted file mode 100755 index c55555f..0000000 --- a/sfshare-gui/src/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -AM_CFLAGS=-Wall @POLKIT_CFLAGS@ @GTK_CFLAGS@ @DBUS_GLIB_CFLAGS@ -# "`$PKG_CONFIG --cflags gtk+-2.0 dbus-glib-1 polkit-gtk-1`" -#$(shell pkg-config --cflags gtk+-2.0 dbus-glib-1 polkit-gtk-1) -AM_LDFLAGS= @POLKIT_LIBS@ @GTK_LIBS@ @DBUS_GLIB_LIBS@ -# "`$PKG_CONFIG --libs gtk+-2.0 dbus-glib-1 polkit-gtk-1`" -#$(shell pkg-config --libs gtk+-2.0 dbus-glib-1 polkit-gtk-1) - - -bin_PROGRAMS = sfshare-gui -sfshare_gui_SOURCES = dbus_client.c dbus_client.h sfshare.h dbus_client_glue.h sfshare.c - diff --git a/sfshare-gui/src/dbus_client.c b/sfshare-gui/src/dbus_client.c deleted file mode 100644 index e285e97..0000000 --- a/sfshare-gui/src/dbus_client.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * 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 library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "dbus_client.h" -#include "sfshare.h" -#include "dbus_client_glue.h" - -#define SFSHARE_DBUS_NAME "org.fedoraproject.SimpleFileShare" -#define SFSHARE_DBUS_PATH "/org/fedoraproject/SimpleFileShare" -#define SFSHARE_DBUS_INTERFACE "org.fedoraproject.SimpleFileShare" - -/* Dbus */ -DBusGConnection *bus; -DBusGProxy *remote_object; -gboolean is_dbus_connected = FALSE; -gboolean is_authorized = FALSE; - -/* Polkit */ -PolkitSubject *subject; -PolkitAuthority *authority; - - -/** Connect to DBUS */ -void -dbus_sfshare_connect ( void ) -{ - if(!is_dbus_connected) - { - GError *error = NULL; - - 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); - - g_error_free (error); - return; - } - - remote_object = dbus_g_proxy_new_for_name (bus, - SFSHARE_DBUS_NAME, - SFSHARE_DBUS_PATH, - SFSHARE_DBUS_INTERFACE); - - is_dbus_connected = TRUE; - } -} - - -/** Disconnect from DBUS - free object */ -void -dbus_sfshare_disconnect ( void ) -{ - if ( is_dbus_connected ) - { - g_object_unref (G_OBJECT (remote_object)); - is_dbus_connected = FALSE; - } -} - -/** Get Polkit Authority */ -void -polkit_sfshare_init () -{ - authority = polkit_authority_get (); -} - -/** Free Polkit objects */ -void -polkit_sfshare_free () -{ - g_object_unref (authority); - g_object_unref (subject); -} - -/** PolicyKit callback */ -static void -check_authorization_cb (PolkitAuthority *authority, - GAsyncResult *res, - gpointer *data) -{ - GError *error; - PolkitAuthorizationResult *result; - - is_authorized = FALSE; - - 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 (); - } - else if (polkit_authorization_result_get_is_challenge (result)) - { - is_authorized = FALSE; - } - else - { - is_authorized = FALSE; - } - } -} - -/** Check privileges vie PolicyKit */ -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))); - - polkit_authority_check_authorization (authority, - subject, - action_id, - NULL, /* PolkitDetails */ - POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, - NULL, - (GAsyncReadyCallback) check_authorization_cb, - NULL); -} - -/** Call daemon D-Bus methot get_share_status */ -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); - - 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; - } - - reload_share_info (); - show_message (GTK_MESSAGE_INFO, "%s" ,"Folder is now shared!", "%s", "Share section was succesfully writed to smb.conf"); -} - - -/** Async call daemon D-Bus methot setup_share */ -void -dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok) -{ - GError *error = NULL; - - const gchar *share[6] = {name, path, comment, read_only, guest_ok, NULL}; - - dbus_sfshare_connect (); - - /* 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; - } -} - - - -/** Reply of delete_share */ -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; - } - - reload_share_info (); - - show_message (GTK_MESSAGE_INFO, "%s", "Share was deleted!", "%s", "Share section was succesfully deleted from smb.conf"); -} - - -/** Async call daemon D-Bus methot delete_share */ -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 deleted file mode 100644 index ce963b2..0000000 --- a/sfshare-gui/src/dbus_client.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#ifndef DBUS_SERVICE_H -#define DBUS_SERVICE_H - -/** Call daemon D-Bus methot get_share_status */ -int dbus_sfshare_get_share (const gchar *path, gchar ***result); -/** Async call daemon D-Bus methot setup_share */ -void dbus_sfshare_set_share (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok); -/** Async call daemon D-Bus methot delete_share */ -void dbus_sfshare_delete_share (const gchar *path); -/** Connect to DBUS */ -void dbus_sfshare_connect ( void ); -/** Disconnect from DBUS - free object */ -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" - -/** Check privileges vie PolicyKit */ -void polkit_sfshare_check (const gchar *action_id); -/** Get Polkit Authority */ -void polkit_sfshare_init(); -/** Free Polkit objects */ -void polkit_sfshare_free(); - - -#endif - diff --git a/sfshare-gui/src/dbus_client_glue.h b/sfshare-gui/src/dbus_client_glue.h deleted file mode 100644 index a494714..0000000 --- a/sfshare-gui/src/dbus_client_glue.h +++ /dev/null @@ -1,138 +0,0 @@ -/* Generated by dbus-binding-tool; do not edit! */ - -#include -#include - -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 deleted file mode 100644 index d223cab..0000000 --- a/sfshare-gui/src/sfshare.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * 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 library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include -#include /* strlen */ - -#include "dbus_client.h" -#include - -#include -#include - - -/** Types of share service */ -typedef enum share_service -{ - NOTHING_SELECTED = -1, - DO_NOT_SHARE, - WIDNOWS_SHARE_SAMBA -} TShare_service; - - -/** Dialog widgets */ -typedef struct _sfsdialog -{ - GtkWidget *window; - - GtkWidget *gui_close; - GtkWidget *gui_save; - - /* Share informations */ - GtkWidget *gui_share; - GtkWidget *gui_sharename; - GtkWidget *gui_comment; - GtkWidget *gui_readonly; - GtkWidget *gui_guestok; - - -} SFSDialog; - -/** Dialog window */ -SFSDialog sfsdialog; - -/** Is directory shared? */ -gboolean shared_smbconf = FALSE; - -/** Did user changed something? */ -gboolean change_in_gui = FALSE; - -/** Path to folder */ -gchar *dir_path; - - -void -sfshare_dialog_destroy () -{ - gtk_widget_destroy (sfsdialog.gui_guestok); - gtk_widget_destroy (sfsdialog.gui_readonly); - gtk_widget_destroy (sfsdialog.gui_comment); - gtk_widget_destroy (sfsdialog.gui_sharename); - gtk_widget_destroy (sfsdialog.gui_share); - gtk_widget_destroy (sfsdialog.gui_save); - gtk_widget_destroy (sfsdialog.gui_close); - gtk_widget_destroy (sfsdialog.window); -} - - -/** On change event - enable Save button */ -void -gui_changed ( void ) -{ - if (!change_in_gui) - { - /* Enale save button */ - gtk_widget_set_sensitive (sfsdialog.gui_save, TRUE); - change_in_gui = TRUE; - } -} - - -/** Show info, error or warning message */ -void -show_message (GtkMessageType type, const gchar *format, gchar *msgtxt, const gchar *format_sec, gchar *msgtxt_sec) -{ - GtkWidget *dialog; - - dialog = gtk_message_dialog_new ( GTK_WINDOW (sfsdialog.window), - GTK_DIALOG_DESTROY_WITH_PARENT, - type, - GTK_BUTTONS_OK, - format, - msgtxt); - - gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG (dialog), - format_sec, - msgtxt_sec); - - gtk_dialog_run ( GTK_DIALOG (dialog)); - - gtk_widget_destroy (dialog); -} - - -/** -* Fill in information about shared directory to GUI -*/ -void -load_share_info ( void ) -{ - - /* [share name], "path =", "commennt =", "read only =", "writable =", "guest ok =" */ - - gchar **share; - gboolean readonly = FALSE; - gboolean guestok = FALSE; - TShare_service share_type = DO_NOT_SHARE; - - shared_smbconf = FALSE; - change_in_gui = FALSE; - - /* Disable save button */ - gtk_widget_set_sensitive (sfsdialog.gui_save, FALSE); - - if (!dbus_sfshare_get_share (dir_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; - } - - share_type = WIDNOWS_SHARE_SAMBA; - - if (!g_strcmp0(share[3], "yes")) - readonly = TRUE; - - if (!g_strcmp0(share[4], "yes")) - guestok = TRUE; - - /* Fill in information about shared directory to GUI */ - gtk_entry_set_text( GTK_ENTRY (sfsdialog.gui_sharename), share[0]); - gtk_entry_set_text( GTK_ENTRY (sfsdialog.gui_comment), share[2]); - gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_readonly), readonly); - gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_guestok), guestok); - gtk_combo_box_set_active (GTK_COMBO_BOX (sfsdialog.gui_share), share_type); - - shared_smbconf = TRUE; - - /* Free vector*/ - g_strfreev(share); - } -} - -void -reload_share_info ( void ) -{ - /* Reload info */ - load_share_info (); -} - -/** -* Check authority via PolicyKit - OnClick Save -*/ -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) - { - const gchar *share_name = gtk_entry_get_text ( GTK_ENTRY (sfsdialog.gui_sharename)); - if (!g_strcmp0(share_name, (""))) - { - show_message(GTK_MESSAGE_WARNING,"%s","Warning!","%s","Share name must be set!"); - return; - } - - polkit_sfshare_check (ACTION_ID_SETUP_SHARE); - } -} - - - -/** -* Save button - call functions to save/change or delete section -*/ -void -save_share ( 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; - } - - /* user want to write share to smb.conf*/ - if (shared_gui) - { - const gchar *yes = "yes"; - const gchar *no = "no"; - - const gchar *ronly; - const gchar *gok; - - 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)); - - if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_readonly))) - ronly = yes; - else - ronly = no; - - if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (sfsdialog.gui_guestok))) - gok = yes; - else - gok = no; - - /* Call dbus method */ - dbus_sfshare_set_share (share_name, dir_path, comment, ronly, gok); - return; - } -} - -/** -* Create main window -*/ -int -main ( int argc, char **argv ) -{ - - GtkBuilder *builder; - const gchar *ui_filename; - GError *error = NULL; - - if (argc < 2) - { - g_warning ("Wrong parameter!"); - exit(1); - } - - /* First parameter is path to shared folder */ - dir_path = argv[1]; - - gtk_init( &argc, &argv ); - - /* Create builder and load interface */ - builder = gtk_builder_new (); - - ui_filename = "/usr/share/sfshare/sfshare_window.ui"; - if (!g_file_test (ui_filename, G_FILE_TEST_EXISTS)) - ui_filename = "../data/sfshare_window.ui"; - - - if (!gtk_builder_add_from_file ( builder, ui_filename, &error )) - { - g_warning ("gtk_builder_add_from_file failed: %s", error->message); - g_error_free (error); - return -1; - } - - /* Obtain widgets that we need */ - sfsdialog.window = GTK_WIDGET ( gtk_builder_get_object( builder, "sfshare_window" )); - 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 (sfsdialog.window)); - - sfsdialog.gui_save = GTK_WIDGET( gtk_builder_get_object( builder, "button_save" )); - g_signal_connect (sfsdialog.gui_save, "clicked", G_CALLBACK (sfshare_authority_check), NULL); - - /* Share info items */ - sfsdialog.gui_share = GTK_WIDGET( gtk_builder_get_object( builder, "combobox_share")); - sfsdialog.gui_sharename = GTK_WIDGET( gtk_builder_get_object( builder, "entry_share_name")); - sfsdialog.gui_comment = GTK_WIDGET( gtk_builder_get_object( builder, "entry_comment")); - sfsdialog.gui_readonly = GTK_WIDGET( gtk_builder_get_object( builder, "checkbutton_readonly")); - sfsdialog.gui_guestok = GTK_WIDGET( gtk_builder_get_object( builder, "checkbutton_guestok")); - - - g_signal_connect (sfsdialog.gui_share, "changed", G_CALLBACK (gui_changed), NULL); - g_signal_connect (sfsdialog.gui_sharename, "changed", G_CALLBACK (gui_changed), NULL); - g_signal_connect (sfsdialog.gui_comment, "changed", G_CALLBACK (gui_changed), NULL); - g_signal_connect (sfsdialog.gui_readonly, "clicked", G_CALLBACK (gui_changed), NULL); - g_signal_connect (sfsdialog.gui_guestok, "clicked", G_CALLBACK (gui_changed), NULL); - - - /* Destroy builder */ - g_object_unref (G_OBJECT( builder )); - - /* Load info about directory */ - load_share_info (); - - /* Show main window and start main loop */ - gtk_widget_show ( sfsdialog.window ); - - /* Dbus and polkit init */ - dbus_sfshare_connect (); - polkit_sfshare_init(); - - gtk_main (); - - dbus_sfshare_disconnect (); - polkit_sfshare_free (); - - return(0); -} diff --git a/sfshare-gui/src/sfshare.h b/sfshare-gui/src/sfshare.h deleted file mode 100644 index 7876e3b..0000000 --- a/sfshare-gui/src/sfshare.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#ifndef SFSHARE_H -#define SFSHARE_H - -/** Shows error, info, warning dialog */ -void show_message (GtkMessageType type, const gchar *format, gchar *msgtxt, const gchar *format_sec, gchar *msgtxt_sec); - -/** Call functions to save/change or delete section */ -void save_share ( void ); - -/** Reload smbd and nmbd */ -void reload_share_info ( void ); - -#endif - -- cgit