2013-01-14 17:58:44 +00:00
/*
* Copyright ( C ) 2013 Intel , Inc
*
* 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 program 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 General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
*
* Author : Thomas Wood < thomas . wood @ intel . com >
*
*/
# include "cc-sharing-panel.h"
# include "shell/cc-hostname-entry.h"
2014-06-23 15:37:34 +02:00
# include "shell/list-box-helper.h"
2013-01-14 17:58:44 +00:00
# include "cc-sharing-resources.h"
# include "vino-preferences.h"
# include "cc-remote-login.h"
# include "file-share-properties.h"
# include "cc-media-sharing.h"
2014-06-20 10:07:46 +02:00
# include "cc-sharing-networks.h"
# include "cc-sharing-switch.h"
# include "org.gnome.SettingsDaemon.Sharing.h"
2013-01-14 17:58:44 +00:00
# include <glib/gi18n.h>
2013-01-28 17:24:15 +00:00
# include <config.h>
2013-01-14 17:58:44 +00:00
CC_PANEL_REGISTER ( CcSharingPanel , cc_sharing_panel )
# define PANEL_PRIVATE(o) \
( G_TYPE_INSTANCE_GET_PRIVATE ( ( o ) , CC_TYPE_SHARING_PANEL , CcSharingPanelPrivate ) )
2013-10-03 10:38:16 +01:00
static void cc_sharing_panel_setup_label_with_hostname ( CcSharingPanel * self , GtkWidget * label ) ;
2014-06-12 16:20:47 +02:00
static GtkWidget * cc_sharing_panel_new_media_sharing_row ( const char * uri_or_path ,
CcSharingPanel * self ) ;
2013-10-03 10:38:16 +01:00
2013-01-14 17:58:44 +00:00
static GtkWidget *
_gtk_builder_get_widget ( GtkBuilder * builder ,
const gchar * name )
{
GtkWidget * w ;
w = ( GtkWidget * ) gtk_builder_get_object ( builder , name ) ;
g_assert ( w ! = NULL ) ;
return w ;
}
# define WID(y) _gtk_builder_get_widget (priv->builder, y)
# define VINO_SCHEMA_ID "org.gnome.Vino"
# define FILE_SHARING_SCHEMA_ID "org.gnome.desktop.file-sharing"
struct _CcSharingPanelPrivate
{
GtkBuilder * builder ;
2013-02-19 09:50:53 +00:00
GtkWidget * master_switch ;
2013-01-14 17:58:44 +00:00
GtkWidget * hostname_entry ;
2014-06-20 10:07:46 +02:00
GDBusProxy * sharing_proxy ;
GtkWidget * media_sharing_switch ;
GtkWidget * personal_file_sharing_switch ;
GtkWidget * screen_sharing_switch ;
2013-01-14 17:58:44 +00:00
GtkWidget * media_sharing_dialog ;
GtkWidget * personal_file_sharing_dialog ;
GtkWidget * remote_login_dialog ;
2013-01-31 12:05:44 +00:00
GCancellable * remote_login_cancellable ;
2013-06-13 11:55:42 +01:00
GCancellable * hostname_cancellable ;
2013-01-14 17:58:44 +00:00
GtkWidget * screen_sharing_dialog ;
2013-01-28 17:24:15 +00:00
2013-11-28 17:23:40 +01:00
GDBusProxy * rfkill ;
2013-01-14 17:58:44 +00:00
} ;
2014-06-20 10:07:46 +02:00
# define OFF_IF_VISIBLE(x) { if (gtk_widget_is_visible(x) && gtk_widget_is_sensitive(x)) gtk_switch_set_active (GTK_SWITCH(x), FALSE); }
2013-02-19 09:50:53 +00:00
static void
cc_sharing_panel_master_switch_notify ( GtkSwitch * gtkswitch ,
GParamSpec * pspec ,
CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
gboolean active ;
active = gtk_switch_get_active ( gtkswitch ) ;
if ( ! active )
{
/* disable all services if the master switch is not active */
2014-06-20 10:07:46 +02:00
OFF_IF_VISIBLE ( priv - > media_sharing_switch ) ;
OFF_IF_VISIBLE ( priv - > personal_file_sharing_switch ) ;
OFF_IF_VISIBLE ( priv - > screen_sharing_switch ) ;
2013-02-19 09:50:53 +00:00
gtk_switch_set_active ( GTK_SWITCH ( WID ( " remote-login-switch " ) ) , FALSE ) ;
}
gtk_widget_set_sensitive ( WID ( " main-list-box " ) , active ) ;
}
static void
cc_sharing_panel_constructed ( GObject * object )
{
CcSharingPanelPrivate * priv = CC_SHARING_PANEL ( object ) - > priv ;
G_OBJECT_CLASS ( cc_sharing_panel_parent_class ) - > constructed ( object ) ;
/* add the master switch */
cc_shell_embed_widget_in_header ( cc_panel_get_shell ( CC_PANEL ( object ) ) ,
2013-07-19 16:30:22 +03:00
gtk_widget_get_parent ( priv - > master_switch ) ) ;
2013-02-19 09:50:53 +00:00
}
2013-01-14 17:58:44 +00:00
static void
cc_sharing_panel_dispose ( GObject * object )
{
CcSharingPanelPrivate * priv = CC_SHARING_PANEL ( object ) - > priv ;
2013-11-28 17:23:40 +01:00
g_clear_object ( & priv - > rfkill ) ;
2013-01-14 17:58:44 +00:00
g_clear_object ( & priv - > builder ) ;
if ( priv - > media_sharing_dialog )
{
gtk_widget_destroy ( priv - > media_sharing_dialog ) ;
priv - > media_sharing_dialog = NULL ;
}
if ( priv - > personal_file_sharing_dialog )
{
gtk_widget_destroy ( priv - > personal_file_sharing_dialog ) ;
priv - > personal_file_sharing_dialog = NULL ;
}
2013-01-31 12:05:44 +00:00
if ( priv - > remote_login_cancellable )
{
g_cancellable_cancel ( priv - > remote_login_cancellable ) ;
g_clear_object ( & priv - > remote_login_cancellable ) ;
}
2013-06-13 11:55:42 +01:00
if ( priv - > hostname_cancellable )
{
g_cancellable_cancel ( priv - > hostname_cancellable ) ;
g_clear_object ( & priv - > hostname_cancellable ) ;
}
2013-01-14 17:58:44 +00:00
if ( priv - > remote_login_dialog )
{
2013-01-31 12:05:44 +00:00
gtk_widget_destroy ( priv - > remote_login_dialog ) ;
priv - > remote_login_dialog = NULL ;
2013-01-14 17:58:44 +00:00
}
if ( priv - > screen_sharing_dialog )
{
gtk_widget_destroy ( priv - > screen_sharing_dialog ) ;
priv - > screen_sharing_dialog = NULL ;
}
2014-06-20 10:07:46 +02:00
g_clear_object ( & priv - > sharing_proxy ) ;
2013-01-14 17:58:44 +00:00
G_OBJECT_CLASS ( cc_sharing_panel_parent_class ) - > dispose ( object ) ;
}
2013-05-28 12:06:12 +02:00
static const char *
cc_sharing_panel_get_help_uri ( CcPanel * panel )
{
2015-03-04 11:33:25 +00:00
return " help:gnome-help/prefs-sharing " ;
2013-05-28 12:06:12 +02:00
}
2013-01-14 17:58:44 +00:00
static void
cc_sharing_panel_class_init ( CcSharingPanelClass * klass )
{
GObjectClass * object_class = G_OBJECT_CLASS ( klass ) ;
2013-05-28 12:06:12 +02:00
CcPanelClass * panel_class = CC_PANEL_CLASS ( klass ) ;
2013-01-14 17:58:44 +00:00
g_type_class_add_private ( klass , sizeof ( CcSharingPanelPrivate ) ) ;
2013-02-19 09:50:53 +00:00
object_class - > constructed = cc_sharing_panel_constructed ;
2013-01-14 17:58:44 +00:00
object_class - > dispose = cc_sharing_panel_dispose ;
2013-05-28 12:06:12 +02:00
panel_class - > get_help_uri = cc_sharing_panel_get_help_uri ;
2013-01-14 17:58:44 +00:00
}
static void
cc_sharing_panel_run_dialog ( CcSharingPanel * self ,
const gchar * dialog_name )
{
CcSharingPanelPrivate * priv = self - > priv ;
GtkWidget * dialog , * parent ;
dialog = WID ( dialog_name ) ;
2013-10-03 10:38:16 +01:00
/* ensure labels with the hostname are updated if the hostname has changed */
cc_sharing_panel_setup_label_with_hostname ( self ,
WID ( " screen-sharing-label " ) ) ;
cc_sharing_panel_setup_label_with_hostname ( self , WID ( " remote-login-label " ) ) ;
cc_sharing_panel_setup_label_with_hostname ( self ,
WID ( " personal-file-sharing-label " ) ) ;
2013-01-14 17:58:44 +00:00
parent = cc_shell_get_toplevel ( cc_panel_get_shell ( CC_PANEL ( self ) ) ) ;
gtk_window_set_transient_for ( GTK_WINDOW ( dialog ) , GTK_WINDOW ( parent ) ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
}
static void
2013-06-13 12:21:30 +02:00
cc_sharing_panel_main_list_box_row_activated ( GtkListBox * listbox ,
GtkListBoxRow * row ,
CcSharingPanel * self )
2013-01-14 17:58:44 +00:00
{
gchar * widget_name , * found ;
2013-06-13 12:21:30 +02:00
widget_name = g_strdup ( gtk_buildable_get_name ( GTK_BUILDABLE ( row ) ) ) ;
2013-01-14 17:58:44 +00:00
if ( ! widget_name )
return ;
2013-06-13 12:21:30 +02:00
gtk_list_box_select_row ( listbox , NULL ) ;
2013-01-14 17:58:44 +00:00
/* replace "button" with "dialog" */
found = g_strrstr ( widget_name , " button " ) ;
if ( ! found )
goto out ;
memcpy ( found , " dialog " , 6 ) ;
cc_sharing_panel_run_dialog ( self , widget_name ) ;
out :
g_free ( widget_name ) ;
}
static gboolean
2013-02-19 09:50:53 +00:00
cc_sharing_panel_switch_to_label_transform_func ( GBinding * binding ,
const GValue * source_value ,
GValue * target_value ,
CcSharingPanel * self )
2013-01-14 17:58:44 +00:00
{
gboolean active ;
if ( ! G_VALUE_HOLDS_BOOLEAN ( source_value ) )
return FALSE ;
if ( ! G_VALUE_HOLDS_STRING ( target_value ) )
return FALSE ;
active = g_value_get_boolean ( source_value ) ;
if ( active )
g_value_set_string ( target_value , C_ ( " service is enabled " , " On " ) ) ;
else
g_value_set_string ( target_value , C_ ( " service is disabled " , " Off " ) ) ;
2013-02-19 09:50:53 +00:00
/* ensure the master switch is active if one of the services is active */
if ( active )
gtk_switch_set_active ( GTK_SWITCH ( self - > priv - > master_switch ) , TRUE ) ;
2013-01-14 17:58:44 +00:00
return TRUE ;
}
2014-06-20 10:07:46 +02:00
static gboolean
cc_sharing_panel_networks_to_label_transform_func ( GBinding * binding ,
const GValue * source_value ,
GValue * target_value ,
CcSharingPanel * self )
{
CcSharingStatus status ;
if ( ! G_VALUE_HOLDS_UINT ( source_value ) )
return FALSE ;
if ( ! G_VALUE_HOLDS_STRING ( target_value ) )
return FALSE ;
status = g_value_get_uint ( source_value ) ;
switch ( status ) {
case CC_SHARING_STATUS_OFF :
g_value_set_string ( target_value , C_ ( " service is disabled " , " Off " ) ) ;
break ;
case CC_SHARING_STATUS_ENABLED :
g_value_set_string ( target_value , C_ ( " service is enabled " , " Enabled " ) ) ;
break ;
case CC_SHARING_STATUS_ACTIVE :
g_value_set_string ( target_value , C_ ( " service is active " , " Active " ) ) ;
break ;
default :
return FALSE ;
}
/* ensure the master switch is active if one of the services is active */
if ( status ! = CC_SHARING_STATUS_OFF )
gtk_switch_set_active ( GTK_SWITCH ( self - > priv - > master_switch ) , TRUE ) ;
return TRUE ;
}
2013-01-14 17:58:44 +00:00
static void
2013-02-19 09:50:53 +00:00
cc_sharing_panel_bind_switch_to_label ( CcSharingPanel * self ,
GtkWidget * gtkswitch ,
GtkWidget * label )
2013-01-14 17:58:44 +00:00
{
g_object_bind_property_full ( gtkswitch , " active " , label , " label " ,
G_BINDING_SYNC_CREATE ,
2013-02-19 09:50:53 +00:00
( GBindingTransformFunc ) cc_sharing_panel_switch_to_label_transform_func ,
NULL , self , NULL ) ;
2013-01-14 17:58:44 +00:00
}
2014-06-20 10:07:46 +02:00
static void
cc_sharing_panel_bind_networks_to_label ( CcSharingPanel * self ,
GtkWidget * networks ,
GtkWidget * label )
{
g_object_bind_property_full ( networks , " status " , label , " label " ,
G_BINDING_SYNC_CREATE ,
( GBindingTransformFunc ) cc_sharing_panel_networks_to_label_transform_func ,
NULL , self , NULL ) ;
}
2013-01-14 17:58:44 +00:00
static void
cc_sharing_panel_bind_switch_to_widgets ( GtkWidget * gtkswitch ,
GtkWidget * first_widget ,
. . . )
{
va_list w ;
GtkWidget * widget ;
va_start ( w , first_widget ) ;
g_object_bind_property ( gtkswitch , " active " , first_widget ,
" sensitive " , G_BINDING_SYNC_CREATE ) ;
while ( ( widget = va_arg ( w , GtkWidget * ) ) )
{
g_object_bind_property ( gtkswitch , " active " , widget ,
" sensitive " , G_BINDING_SYNC_CREATE ) ;
}
va_end ( w ) ;
}
static void
2014-06-12 16:20:47 +02:00
cc_sharing_panel_add_folder ( GtkListBox * box ,
GtkListBoxRow * row ,
2013-01-14 17:58:44 +00:00
CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
GtkWidget * dialog ;
2015-02-09 11:28:24 +01:00
gchar * folder = NULL ;
2013-11-14 23:55:04 +01:00
gboolean matching = FALSE ;
2014-06-12 16:20:47 +02:00
GList * rows , * l ;
if ( ! GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( row ) , " is-add " ) ) )
return ;
2013-01-14 17:58:44 +00:00
dialog = gtk_file_chooser_dialog_new ( _ ( " Choose a Folder " ) ,
2014-06-12 16:20:47 +02:00
GTK_WINDOW ( gtk_widget_get_toplevel ( GTK_WIDGET ( box ) ) ) ,
2013-01-14 17:58:44 +00:00
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ,
2013-07-19 15:58:09 +03:00
_ ( " _Cancel " ) , GTK_RESPONSE_CANCEL ,
_ ( " _Open " ) , GTK_RESPONSE_ACCEPT ,
2013-01-14 17:58:44 +00:00
NULL ) ;
2014-08-07 13:04:09 +02:00
gtk_file_chooser_set_local_only ( GTK_FILE_CHOOSER ( dialog ) , FALSE ) ;
2015-02-09 11:28:24 +01:00
if ( gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ! = GTK_RESPONSE_ACCEPT )
goto bail ;
2013-01-14 17:58:44 +00:00
gtk_widget_hide ( dialog ) ;
2014-06-12 16:20:47 +02:00
box = GTK_LIST_BOX ( WID ( " shared-folders-listbox " ) ) ;
rows = gtk_container_get_children ( GTK_CONTAINER ( box ) ) ;
2013-01-14 17:58:44 +00:00
2014-06-26 16:08:12 +02:00
folder = gtk_file_chooser_get_uri ( GTK_FILE_CHOOSER ( dialog ) ) ;
2013-11-14 09:16:34 +01:00
if ( ! folder | | g_str_equal ( folder , " " ) )
goto bail ;
g_debug ( " Trying to add %s " , folder ) ;
2013-01-14 17:58:44 +00:00
2014-06-12 16:20:47 +02:00
for ( l = rows ; l ! = NULL ; l = l - > next )
2013-10-02 16:42:18 +01:00
{
2014-06-12 16:20:47 +02:00
const char * string ;
2013-10-02 16:42:18 +01:00
2014-06-12 16:20:47 +02:00
string = g_object_get_data ( G_OBJECT ( l - > data ) , " path " ) ;
2013-11-14 09:25:30 +01:00
matching = ( g_strcmp0 ( string , folder ) = = 0 ) ;
2013-10-02 16:42:18 +01:00
if ( matching )
2013-11-14 09:16:34 +01:00
{
g_debug ( " Found a duplicate for %s " , folder ) ;
break ;
}
2013-10-02 16:42:18 +01:00
}
2013-11-14 09:16:34 +01:00
if ( ! matching )
2014-06-12 16:20:47 +02:00
{
GtkWidget * row ;
int i ;
row = cc_sharing_panel_new_media_sharing_row ( folder , self ) ;
i = g_list_length ( rows ) ;
gtk_list_box_insert ( GTK_LIST_BOX ( box ) , row , i - 1 ) ;
}
2014-06-24 18:41:42 +02:00
cc_list_box_adjust_scrolling ( GTK_LIST_BOX ( box ) ) ;
2013-01-14 17:58:44 +00:00
2013-11-14 09:16:34 +01:00
bail :
2013-01-14 17:58:44 +00:00
g_free ( folder ) ;
gtk_widget_destroy ( dialog ) ;
}
static void
cc_sharing_panel_remove_folder ( GtkButton * button ,
CcSharingPanel * self )
{
2014-06-23 15:37:34 +02:00
CcSharingPanelPrivate * priv = self - > priv ;
2014-06-12 16:20:47 +02:00
GtkWidget * row ;
2013-01-14 17:58:44 +00:00
2014-06-12 16:20:47 +02:00
row = g_object_get_data ( G_OBJECT ( button ) , " row " ) ;
gtk_widget_destroy ( row ) ;
2014-06-24 18:41:42 +02:00
cc_list_box_adjust_scrolling ( GTK_LIST_BOX ( WID ( " shared-folders-listbox " ) ) ) ;
2013-01-14 17:58:44 +00:00
}
static void
cc_sharing_panel_media_sharing_dialog_response ( GtkDialog * dialog ,
gint reponse_id ,
CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
GPtrArray * folders ;
2014-06-12 16:20:47 +02:00
GtkWidget * box ;
GList * rows , * l ;
2013-01-14 17:58:44 +00:00
2014-06-12 16:20:47 +02:00
box = WID ( " shared-folders-listbox " ) ;
rows = gtk_container_get_children ( GTK_CONTAINER ( box ) ) ;
2013-01-14 17:58:44 +00:00
folders = g_ptr_array_new_with_free_func ( g_free ) ;
2014-06-12 16:20:47 +02:00
for ( l = rows ; l ! = NULL ; l = l - > next )
2013-01-14 17:58:44 +00:00
{
2014-06-12 16:20:47 +02:00
const char * folder ;
2013-01-14 17:58:44 +00:00
2014-06-12 16:20:47 +02:00
folder = g_object_get_data ( G_OBJECT ( l - > data ) , " path " ) ;
if ( folder = = NULL )
continue ;
g_ptr_array_add ( folders , g_strdup ( folder ) ) ;
2013-01-14 17:58:44 +00:00
}
g_ptr_array_add ( folders , NULL ) ;
2014-06-20 10:07:46 +02:00
cc_media_sharing_set_preferences ( ( gchar * * ) folders - > pdata ) ;
2013-01-14 17:58:44 +00:00
g_ptr_array_free ( folders , TRUE ) ;
}
2014-06-12 16:20:47 +02:00
# define ICON_NAME_FOLDER "folder-symbolic"
# define ICON_NAME_FOLDER_DESKTOP "user-desktop-symbolic"
# define ICON_NAME_FOLDER_DOCUMENTS "folder-documents-symbolic"
# define ICON_NAME_FOLDER_DOWNLOAD "folder-download-symbolic"
# define ICON_NAME_FOLDER_MUSIC "folder-music-symbolic"
# define ICON_NAME_FOLDER_PICTURES "folder-pictures-symbolic"
# define ICON_NAME_FOLDER_PUBLIC_SHARE "folder-publicshare-symbolic"
# define ICON_NAME_FOLDER_TEMPLATES "folder-templates-symbolic"
# define ICON_NAME_FOLDER_VIDEOS "folder-videos-symbolic"
# define ICON_NAME_FOLDER_SAVED_SEARCH "folder-saved-search-symbolic"
static GIcon *
special_directory_get_gicon ( GUserDirectory directory )
{
# define ICON_CASE(x) \
case G_USER_DIRECTORY_ # # x : \
return g_themed_icon_new_with_default_fallbacks ( ICON_NAME_FOLDER_ # # x ) ;
switch ( directory )
{
ICON_CASE ( DESKTOP ) ;
ICON_CASE ( DOCUMENTS ) ;
ICON_CASE ( DOWNLOAD ) ;
ICON_CASE ( MUSIC ) ;
ICON_CASE ( PICTURES ) ;
ICON_CASE ( PUBLIC_SHARE ) ;
ICON_CASE ( TEMPLATES ) ;
ICON_CASE ( VIDEOS ) ;
default :
return g_themed_icon_new_with_default_fallbacks ( ICON_NAME_FOLDER ) ;
}
# undef ICON_CASE
}
static GtkWidget *
cc_sharing_panel_new_media_sharing_row ( const char * uri_or_path ,
CcSharingPanel * self )
{
GtkWidget * row , * box , * w ;
GUserDirectory dir = G_USER_N_DIRECTORIES ;
GIcon * icon ;
guint i ;
char * basename , * path ;
GFile * file ;
file = g_file_new_for_commandline_arg ( uri_or_path ) ;
path = g_file_get_path ( file ) ;
g_object_unref ( file ) ;
row = gtk_list_box_row_new ( ) ;
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
gtk_container_set_border_width ( GTK_CONTAINER ( box ) , 12 ) ;
gtk_container_add ( GTK_CONTAINER ( row ) , box ) ;
/* Find the icon and create it */
for ( i = 0 ; i < G_USER_N_DIRECTORIES ; i + + )
{
if ( g_strcmp0 ( path , g_get_user_special_dir ( i ) ) = = 0 )
{
dir = i ;
break ;
}
}
icon = special_directory_get_gicon ( dir ) ;
w = gtk_image_new_from_gicon ( icon , GTK_ICON_SIZE_MENU ) ;
gtk_widget_set_margin_end ( w , 12 ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , w ) ;
g_object_unref ( icon ) ;
/* Label */
basename = g_filename_display_basename ( path ) ;
w = gtk_label_new ( basename ) ;
g_free ( basename ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , w ) ;
/* Remove button */
w = gtk_button_new_from_icon_name ( " window-close-symbolic " , GTK_ICON_SIZE_SMALL_TOOLBAR ) ;
gtk_button_set_relief ( GTK_BUTTON ( w ) , GTK_RELIEF_NONE ) ;
gtk_widget_set_margin_top ( w , 3 ) ;
gtk_widget_set_margin_bottom ( w , 3 ) ;
gtk_widget_set_margin_end ( w , 12 ) ;
gtk_widget_set_valign ( w , GTK_ALIGN_CENTER ) ;
gtk_box_pack_end ( GTK_BOX ( box ) , w , FALSE , FALSE , 0 ) ;
g_signal_connect ( G_OBJECT ( w ) , " clicked " ,
G_CALLBACK ( cc_sharing_panel_remove_folder ) , self ) ;
g_object_set_data ( G_OBJECT ( w ) , " row " , row ) ;
g_object_set_data_full ( G_OBJECT ( row ) , " path " , g_strdup ( path ) , g_free ) ;
gtk_widget_show_all ( row ) ;
return row ;
}
static GtkWidget *
cc_sharing_panel_new_add_media_sharing_row ( CcSharingPanel * self )
{
GtkWidget * row , * box , * w ;
row = gtk_list_box_row_new ( ) ;
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
gtk_container_set_border_width ( GTK_CONTAINER ( box ) , 12 ) ;
gtk_container_add ( GTK_CONTAINER ( row ) , box ) ;
w = gtk_image_new_from_icon_name ( " list-add-symbolic " , GTK_ICON_SIZE_SMALL_TOOLBAR ) ;
gtk_container_add ( GTK_CONTAINER ( box ) , w ) ;
gtk_widget_set_hexpand ( w , TRUE ) ;
gtk_widget_set_margin_top ( w , 6 ) ;
gtk_widget_set_margin_bottom ( w , 6 ) ;
g_object_set_data ( G_OBJECT ( w ) , " row " , row ) ;
g_object_set_data ( G_OBJECT ( row ) , " is-add " , GINT_TO_POINTER ( 1 ) ) ;
gtk_widget_show_all ( row ) ;
return row ;
}
2013-01-14 17:58:44 +00:00
static void
cc_sharing_panel_setup_media_sharing_dialog ( CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
gchar * * folders , * * list ;
2014-06-20 10:07:46 +02:00
GtkWidget * box , * networks , * grid , * w ;
2013-01-15 17:54:00 +01:00
char * path ;
path = g_find_program_in_path ( " rygel " ) ;
if ( path = = NULL )
{
gtk_widget_hide ( WID ( " media-sharing-button " ) ) ;
return ;
}
g_free ( path ) ;
2013-01-14 17:58:44 +00:00
g_signal_connect ( WID ( " media-sharing-dialog " ) , " response " ,
G_CALLBACK ( cc_sharing_panel_media_sharing_dialog_response ) ,
self ) ;
2014-06-20 10:07:46 +02:00
cc_media_sharing_get_preferences ( & folders ) ;
2013-01-14 17:58:44 +00:00
2014-06-12 16:20:47 +02:00
box = WID ( " shared-folders-listbox " ) ;
gtk_list_box_set_header_func ( GTK_LIST_BOX ( box ) ,
2014-06-23 15:37:34 +02:00
cc_list_box_update_header_func , NULL ,
2014-06-12 16:20:47 +02:00
NULL ) ;
2014-06-26 15:58:52 +02:00
cc_list_box_setup_scrolling ( GTK_LIST_BOX ( box ) , 3 ) ;
2014-06-12 16:20:47 +02:00
2013-01-14 17:58:44 +00:00
list = folders ;
while ( list & & * list )
{
2014-06-12 16:20:47 +02:00
GtkWidget * row ;
row = cc_sharing_panel_new_media_sharing_row ( * list , self ) ;
gtk_list_box_insert ( GTK_LIST_BOX ( box ) , row , - 1 ) ;
2013-01-14 17:58:44 +00:00
list + + ;
}
2014-06-12 16:20:47 +02:00
gtk_list_box_insert ( GTK_LIST_BOX ( box ) ,
cc_sharing_panel_new_add_media_sharing_row ( self ) , - 1 ) ;
2014-06-24 18:41:42 +02:00
cc_list_box_adjust_scrolling ( GTK_LIST_BOX ( box ) ) ;
2014-06-12 16:20:47 +02:00
g_signal_connect ( G_OBJECT ( box ) , " row-activated " ,
G_CALLBACK ( cc_sharing_panel_add_folder ) , self ) ;
2013-01-14 17:58:44 +00:00
g_strfreev ( folders ) ;
2014-06-20 10:07:46 +02:00
networks = cc_sharing_networks_new ( self - > priv - > sharing_proxy , " rygel " ) ;
grid = WID ( " grid4 " ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , networks , 0 , 4 , 2 , 1 ) ;
gtk_widget_show ( networks ) ;
w = cc_sharing_switch_new ( networks ) ;
gtk_header_bar_pack_start ( GTK_HEADER_BAR ( WID ( " media-sharing-headerbar " ) ) , w ) ;
self - > priv - > media_sharing_switch = w ;
cc_sharing_panel_bind_networks_to_label ( self , networks ,
WID ( " media-sharing-status-label " ) ) ;
2013-01-14 17:58:44 +00:00
}
static gboolean
cc_sharing_panel_label_activate_link ( GtkLabel * label ,
gchar * uri ,
GtkMenu * menu )
{
gtk_menu_popup ( menu , NULL , NULL , NULL , NULL , 0 , gtk_get_current_event_time ( ) ) ;
g_object_set_data_full ( G_OBJECT ( menu ) , " uri-text " , g_strdup ( uri ) , g_free ) ;
return TRUE ;
}
static void
copy_uri_to_clipboard ( GtkMenuItem * item ,
GtkMenu * menu )
{
GtkClipboard * clipboard ;
const gchar * text ;
text = g_object_get_data ( G_OBJECT ( menu ) , " uri-text " ) ;
clipboard = gtk_clipboard_get ( GDK_SELECTION_CLIPBOARD ) ;
gtk_clipboard_set_text ( clipboard , text , - 1 ) ;
}
2013-06-13 11:55:42 +01:00
static void
2016-03-24 16:23:25 +01:00
cc_sharing_panel_setup_label ( CcSharingPanel * self ,
GtkWidget * label ,
const gchar * hostname )
2013-06-13 11:55:42 +01:00
{
2016-03-24 16:23:25 +01:00
CcSharingPanelPrivate * priv = self - > priv ;
2013-06-13 11:55:42 +01:00
gchar * text ;
2013-10-03 10:38:16 +01:00
2016-03-24 16:23:25 +01:00
if ( label = = WID ( " personal-file-sharing-label " ) )
text = g_strdup_printf ( _ ( " Personal File Sharing allows you to share your Public folder with others on your current network using: <a href= \" dav://%s \" >dav://%s</a> " ) , hostname , hostname ) ;
else if ( label = = WID ( " remote-login-label " ) )
text = g_strdup_printf ( _ ( " Allow remote users to connect using the Secure Shell command: \n <a href= \" ssh %s \" >ssh %s</a> " ) , hostname , hostname ) ;
else if ( label = = WID ( " screen-sharing-label " ) )
text = g_strdup_printf ( _ ( " Allow remote users to view or control your screen by connecting to: <a href= \" vnc://%s \" >vnc://%s</a> " ) , hostname , hostname ) ;
else
g_assert_not_reached ( ) ;
2013-06-13 11:55:42 +01:00
2016-03-24 16:23:25 +01:00
gtk_label_set_label ( GTK_LABEL ( label ) , text ) ;
2013-06-13 11:55:42 +01:00
g_free ( text ) ;
}
typedef struct
{
CcSharingPanel * panel ;
GtkWidget * label ;
} GetHostNameData ;
static void
cc_sharing_panel_get_host_name_fqdn_done ( GDBusConnection * connection ,
GAsyncResult * res ,
GetHostNameData * data )
{
GError * error = NULL ;
GVariant * variant ;
const gchar * fqdn ;
variant = g_dbus_connection_call_finish ( connection , res , & error ) ;
if ( variant = = NULL )
{
/* Avahi service may not be available */
g_debug ( " Error calling GetHostNameFqdn: %s " , error - > message ) ;
if ( ! g_error_matches ( error , G_IO_ERROR , G_IO_ERROR_CANCELLED ) )
{
gchar * hostname ;
hostname = cc_hostname_entry_get_hostname ( CC_HOSTNAME_ENTRY ( data - > panel - > priv - > hostname_entry ) ) ;
2016-03-24 16:23:25 +01:00
cc_sharing_panel_setup_label ( data - > panel , data - > label , hostname ) ;
2013-06-13 11:55:42 +01:00
g_free ( hostname ) ;
}
g_free ( data ) ;
g_error_free ( error ) ;
return ;
}
g_variant_get ( variant , " (&s) " , & fqdn ) ;
2016-03-24 16:23:25 +01:00
cc_sharing_panel_setup_label ( data - > panel , data - > label , fqdn ) ;
2013-06-13 11:55:42 +01:00
g_variant_unref ( variant ) ;
g_object_unref ( connection ) ;
g_free ( data ) ;
}
static void
cc_sharing_panel_bus_ready ( GObject * object ,
GAsyncResult * res ,
GetHostNameData * data )
{
GDBusConnection * connection ;
GError * error = NULL ;
connection = g_bus_get_finish ( res , & error ) ;
if ( connection = = NULL )
{
g_warning ( " Could not connect to system bus: %s " , error - > message ) ;
if ( ! g_error_matches ( error , G_IO_ERROR , G_IO_ERROR_CANCELLED ) )
{
gchar * hostname ;
hostname = cc_hostname_entry_get_hostname ( CC_HOSTNAME_ENTRY ( data - > panel - > priv - > hostname_entry ) ) ;
2016-03-24 16:23:25 +01:00
cc_sharing_panel_setup_label ( data - > panel , data - > label , hostname ) ;
2013-06-13 11:55:42 +01:00
g_free ( hostname ) ;
}
g_error_free ( error ) ;
g_free ( data ) ;
return ;
}
g_dbus_connection_call ( connection ,
" org.freedesktop.Avahi " ,
" / " ,
" org.freedesktop.Avahi.Server " ,
" GetHostNameFqdn " ,
NULL ,
( GVariantType * ) " (s) " ,
G_DBUS_CALL_FLAGS_NONE ,
- 1 ,
NULL ,
( GAsyncReadyCallback ) cc_sharing_panel_get_host_name_fqdn_done ,
data ) ;
}
2013-01-14 17:58:44 +00:00
static void
cc_sharing_panel_setup_label_with_hostname ( CcSharingPanel * self ,
GtkWidget * label )
{
GtkWidget * menu ;
GtkWidget * menu_item ;
2013-06-13 11:55:42 +01:00
GetHostNameData * get_hostname_data ;
2013-01-14 17:58:44 +00:00
/* create the menu */
menu = gtk_menu_new ( ) ;
menu_item = gtk_menu_item_new_with_label ( _ ( " Copy " ) ) ;
gtk_widget_show ( menu_item ) ;
g_signal_connect ( menu_item , " activate " , G_CALLBACK ( copy_uri_to_clipboard ) ,
menu ) ;
gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ) , menu_item ) ;
/* show the menu when the link is activated */
g_signal_connect ( label , " activate-link " ,
G_CALLBACK ( cc_sharing_panel_label_activate_link ) , menu ) ;
/* destroy the menu when the label is destroyed */
g_signal_connect_swapped ( label , " destroy " , G_CALLBACK ( gtk_widget_destroy ) ,
menu ) ;
2013-06-13 11:55:42 +01:00
/* set the hostname */
get_hostname_data = g_new ( GetHostNameData , 1 ) ;
get_hostname_data - > panel = self ;
get_hostname_data - > label = label ;
g_bus_get ( G_BUS_TYPE_SYSTEM , NULL ,
( GAsyncReadyCallback ) cc_sharing_panel_bus_ready ,
get_hostname_data ) ;
2013-01-14 17:58:44 +00:00
}
static gboolean
file_sharing_get_require_password ( GValue * value ,
GVariant * variant ,
gpointer user_data )
{
if ( g_str_equal ( g_variant_get_string ( variant , NULL ) , " always " ) )
g_value_set_boolean ( value , TRUE ) ;
else
g_value_set_boolean ( value , FALSE ) ;
return TRUE ;
}
static GVariant *
file_sharing_set_require_password ( const GValue * value ,
const GVariantType * type ,
gpointer user_data )
{
if ( g_value_get_boolean ( value ) )
return g_variant_new_string ( " always " ) ;
else
return g_variant_new_string ( " never " ) ;
}
static void
file_sharing_password_changed ( GtkEntry * entry )
{
file_share_write_out_password ( gtk_entry_get_text ( entry ) ) ;
}
static void
cc_sharing_panel_setup_personal_file_sharing_dialog ( CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
GSettings * settings ;
2014-06-20 10:07:46 +02:00
GtkWidget * networks , * grid , * w ;
2013-01-14 17:58:44 +00:00
cc_sharing_panel_bind_switch_to_widgets ( WID ( " personal-file-sharing-require-password-switch " ) ,
WID ( " personal-file-sharing-password-entry " ) ,
WID ( " personal-file-sharing-password-label " ) ,
NULL ) ;
cc_sharing_panel_setup_label_with_hostname ( self ,
WID ( " personal-file-sharing-label " ) ) ;
/* the password cannot be read, so just make sure the entry is not empty */
gtk_entry_set_text ( GTK_ENTRY ( WID ( " personal-file-sharing-password-entry " ) ) ,
" password " ) ;
settings = g_settings_new ( FILE_SHARING_SCHEMA_ID ) ;
g_settings_bind_with_mapping ( settings , " require-password " ,
WID ( " personal-file-sharing-require-password-switch " ) ,
" active " ,
G_SETTINGS_BIND_DEFAULT ,
file_sharing_get_require_password ,
file_sharing_set_require_password , NULL , NULL ) ;
g_signal_connect ( WID ( " personal-file-sharing-password-entry " ) ,
" notify::text " , G_CALLBACK ( file_sharing_password_changed ) ,
NULL ) ;
2014-06-20 10:07:46 +02:00
networks = cc_sharing_networks_new ( self - > priv - > sharing_proxy , " gnome-user-share-webdav " ) ;
grid = WID ( " grid2 " ) ;
gtk_grid_attach ( GTK_GRID ( grid ) , networks , 0 , 3 , 2 , 1 ) ;
gtk_widget_show ( networks ) ;
w = cc_sharing_switch_new ( networks ) ;
gtk_header_bar_pack_start ( GTK_HEADER_BAR ( WID ( " personal-file-sharing-headerbar " ) ) , w ) ;
self - > priv - > personal_file_sharing_switch = w ;
cc_sharing_panel_bind_networks_to_label ( self ,
networks ,
WID ( " personal-file-sharing-status-label " ) ) ;
2013-01-14 17:58:44 +00:00
}
static void
remote_login_switch_activate ( GtkSwitch * remote_login_switch ,
2013-01-31 12:05:44 +00:00
GParamSpec * pspec ,
2013-01-14 17:58:44 +00:00
CcSharingPanel * self )
{
2013-01-31 12:05:44 +00:00
cc_remote_login_set_enabled ( self - > priv - > remote_login_cancellable , remote_login_switch ) ;
2013-01-14 17:58:44 +00:00
}
static void
cc_sharing_panel_setup_remote_login_dialog ( CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
2013-02-19 09:50:53 +00:00
cc_sharing_panel_bind_switch_to_label ( self , WID ( " remote-login-switch " ) ,
2013-01-14 17:58:44 +00:00
WID ( " remote-login-status-label " ) ) ;
cc_sharing_panel_setup_label_with_hostname ( self , WID ( " remote-login-label " ) ) ;
g_signal_connect ( WID ( " remote-login-switch " ) , " notify::active " ,
G_CALLBACK ( remote_login_switch_activate ) , self ) ;
gtk_widget_set_sensitive ( WID ( " remote-login-switch " ) , FALSE ) ;
2013-01-31 12:05:44 +00:00
cc_remote_login_get_enabled ( self - > priv - > remote_login_cancellable ,
GTK_SWITCH ( WID ( " remote-login-switch " ) ) ,
WID ( " remote-login-button " ) ) ;
2013-01-14 17:58:44 +00:00
}
static gboolean
cc_sharing_panel_check_schema_available ( CcSharingPanel * self ,
const gchar * schema_id )
{
2014-11-29 16:39:34 +01:00
GSettingsSchemaSource * source ;
GSettingsSchema * schema ;
2013-01-14 17:58:44 +00:00
2014-11-29 16:39:34 +01:00
source = g_settings_schema_source_get_default ( ) ;
if ( ! source )
2013-01-14 17:58:44 +00:00
return FALSE ;
2014-11-29 16:39:34 +01:00
schema = g_settings_schema_source_lookup ( source , schema_id , TRUE ) ;
if ( ! schema )
return FALSE ;
2013-01-14 17:58:44 +00:00
2014-11-29 16:39:34 +01:00
g_settings_schema_unref ( schema ) ;
return TRUE ;
2013-01-14 17:58:44 +00:00
}
2013-06-24 16:31:58 -03:00
static void
screen_sharing_show_cb ( GtkWidget * widget , CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( WID ( " show-password-checkbutton " ) ) ,
FALSE ) ;
}
2013-07-29 12:34:25 -03:00
static void
screen_sharing_hide_cb ( GtkWidget * widget , CcSharingPanel * self )
{
2014-02-15 19:29:22 +00:00
GtkToggleButton * ac_radio ;
2013-07-29 12:34:25 -03:00
GtkEntry * pw_entry ;
const gchar * password ;
CcSharingPanelPrivate * priv = self - > priv ;
2014-02-15 19:29:22 +00:00
ac_radio = GTK_TOGGLE_BUTTON ( WID ( " approve-connections-radiobutton " ) ) ;
2013-07-29 12:34:25 -03:00
pw_entry = GTK_ENTRY ( WID ( " remote-control-password-entry " ) ) ;
password = gtk_entry_get_text ( pw_entry ) ;
if ( password = = NULL | | * password = = ' \0 ' )
2014-02-15 19:29:22 +00:00
gtk_toggle_button_set_active ( ac_radio , TRUE ) ;
2013-07-29 12:34:25 -03:00
}
2013-06-26 09:07:14 -03:00
# define MAX_PASSWORD_SIZE 8
static void
screen_sharing_password_insert_text_cb ( GtkEditable * editable ,
gchar * new_text ,
gint new_text_length ,
gpointer position ,
gpointer user_data )
{
int l , available_size ;
l = gtk_entry_buffer_get_bytes ( gtk_entry_get_buffer ( GTK_ENTRY ( editable ) ) ) ;
if ( l + new_text_length < = MAX_PASSWORD_SIZE )
return ;
g_signal_stop_emission_by_name ( editable , " insert-text " ) ;
gtk_widget_error_bell ( GTK_WIDGET ( editable ) ) ;
available_size = g_utf8_strlen ( new_text , MAX_PASSWORD_SIZE - l ) ;
if ( available_size = = 0 )
return ;
g_signal_handlers_block_by_func ( editable ,
( gpointer ) screen_sharing_password_insert_text_cb ,
user_data ) ;
gtk_editable_insert_text ( editable , new_text , available_size , position ) ;
g_signal_handlers_unblock_by_func ( editable ,
( gpointer ) screen_sharing_password_insert_text_cb ,
user_data ) ;
}
# undef MAX_PASSWORD_SIZE
2013-01-14 17:58:44 +00:00
static void
cc_sharing_panel_setup_screen_sharing_dialog ( CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv ;
GSettings * settings ;
2014-06-20 10:07:46 +02:00
GtkWidget * networks , * box , * w ;
2013-01-14 17:58:44 +00:00
2014-02-15 19:29:22 +00:00
cc_sharing_panel_bind_switch_to_widgets ( WID ( " require-password-radiobutton " ) ,
2013-09-17 16:35:25 +01:00
WID ( " password-grid " ) ,
2013-01-14 17:58:44 +00:00
NULL ) ;
cc_sharing_panel_setup_label_with_hostname ( self ,
WID ( " screen-sharing-label " ) ) ;
/* settings bindings */
settings = g_settings_new ( VINO_SCHEMA_ID ) ;
g_settings_bind ( settings , " view-only " , WID ( " remote-control-switch " ) ,
" active " ,
G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN ) ;
g_settings_bind ( settings , " prompt-enabled " ,
2014-02-15 19:29:22 +00:00
WID ( " approve-connections-radiobutton " ) , " active " ,
2013-01-14 17:58:44 +00:00
G_SETTINGS_BIND_DEFAULT ) ;
g_settings_bind_with_mapping ( settings , " authentication-methods " ,
2014-02-15 19:29:22 +00:00
WID ( " require-password-radiobutton " ) ,
2013-01-14 17:58:44 +00:00
" active " ,
G_SETTINGS_BIND_DEFAULT ,
vino_get_authtype , vino_set_authtype , NULL , NULL ) ;
g_settings_bind_with_mapping ( settings , " vnc-password " ,
WID ( " remote-control-password-entry " ) ,
" text " ,
G_SETTINGS_BIND_DEFAULT ,
vino_get_password , vino_set_password , NULL , NULL ) ;
2013-01-23 10:28:44 +00:00
g_object_bind_property ( WID ( " show-password-checkbutton " ) , " active " ,
WID ( " remote-control-password-entry " ) , " visibility " ,
G_BINDING_SYNC_CREATE ) ;
2013-06-24 16:31:58 -03:00
/* make sure the password entry is hidden by default */
g_signal_connect ( priv - > screen_sharing_dialog , " show " ,
G_CALLBACK ( screen_sharing_show_cb ) , self ) ;
2013-06-26 09:07:14 -03:00
2013-07-29 12:34:25 -03:00
g_signal_connect ( priv - > screen_sharing_dialog , " hide " ,
G_CALLBACK ( screen_sharing_hide_cb ) , self ) ;
2013-06-26 09:07:14 -03:00
/* accept at most 8 bytes in password entry */
g_signal_connect ( WID ( " remote-control-password-entry " ) , " insert-text " ,
G_CALLBACK ( screen_sharing_password_insert_text_cb ) , self ) ;
2014-06-20 10:07:46 +02:00
networks = cc_sharing_networks_new ( self - > priv - > sharing_proxy , " vino-server " ) ;
box = WID ( " remote-control-box " ) ;
gtk_box_pack_end ( GTK_BOX ( box ) , networks , TRUE , TRUE , 0 ) ;
gtk_widget_show ( networks ) ;
w = cc_sharing_switch_new ( networks ) ;
gtk_header_bar_pack_start ( GTK_HEADER_BAR ( WID ( " screen-sharing-headerbar " ) ) , w ) ;
self - > priv - > screen_sharing_switch = w ;
cc_sharing_panel_bind_networks_to_label ( self , networks ,
WID ( " screen-sharing-status-label " ) ) ;
2013-01-14 17:58:44 +00:00
}
static void
cc_sharing_panel_init ( CcSharingPanel * self )
{
CcSharingPanelPrivate * priv = self - > priv = PANEL_PRIVATE ( self ) ;
2013-07-19 16:30:22 +03:00
GtkWidget * box ;
2013-01-14 17:58:44 +00:00
GError * err = NULL ;
gchar * objects [ ] = {
" sharing-panel " ,
" media-sharing-dialog " ,
" personal-file-sharing-dialog " ,
" remote-login-dialog " ,
" screen-sharing-dialog " ,
NULL } ;
2014-06-20 10:07:46 +02:00
GError * error = NULL ;
2013-01-14 17:58:44 +00:00
g_resources_register ( cc_sharing_get_resource ( ) ) ;
priv - > builder = gtk_builder_new ( ) ;
gtk_builder_add_objects_from_resource ( priv - > builder ,
" /org/gnome/control-center/sharing/sharing.ui " ,
objects , & err ) ;
if ( err )
g_error ( " Error loading CcSharingPanel user interface: %s " , err - > message ) ;
priv - > hostname_entry = WID ( " hostname-entry " ) ;
gtk_container_add ( GTK_CONTAINER ( self ) , WID ( " sharing-panel " ) ) ;
2013-06-13 12:21:30 +02:00
g_signal_connect ( WID ( " main-list-box " ) , " row-activated " ,
G_CALLBACK ( cc_sharing_panel_main_list_box_row_activated ) , self ) ;
2013-01-14 17:58:44 +00:00
2013-06-13 11:55:42 +01:00
priv - > hostname_cancellable = g_cancellable_new ( ) ;
2013-01-14 17:58:44 +00:00
priv - > media_sharing_dialog = WID ( " media-sharing-dialog " ) ;
priv - > personal_file_sharing_dialog = WID ( " personal-file-sharing-dialog " ) ;
priv - > remote_login_dialog = WID ( " remote-login-dialog " ) ;
2013-01-31 12:05:44 +00:00
priv - > remote_login_cancellable = g_cancellable_new ( ) ;
2013-01-14 17:58:44 +00:00
priv - > screen_sharing_dialog = WID ( " screen-sharing-dialog " ) ;
g_signal_connect ( priv - > media_sharing_dialog , " response " ,
G_CALLBACK ( gtk_widget_hide ) , NULL ) ;
g_signal_connect ( priv - > personal_file_sharing_dialog , " response " ,
G_CALLBACK ( gtk_widget_hide ) , NULL ) ;
g_signal_connect ( priv - > remote_login_dialog , " response " ,
G_CALLBACK ( gtk_widget_hide ) , NULL ) ;
g_signal_connect ( priv - > screen_sharing_dialog , " response " ,
G_CALLBACK ( gtk_widget_hide ) , NULL ) ;
2013-06-13 12:21:30 +02:00
gtk_list_box_set_activate_on_single_click ( GTK_LIST_BOX ( WID ( " main-list-box " ) ) ,
2013-01-14 17:58:44 +00:00
TRUE ) ;
2013-06-13 12:21:30 +02:00
gtk_list_box_set_header_func ( GTK_LIST_BOX ( WID ( " main-list-box " ) ) ,
2014-06-23 15:37:34 +02:00
cc_list_box_update_header_func ,
2013-06-13 12:21:30 +02:00
NULL , NULL ) ;
2013-01-14 17:58:44 +00:00
2013-02-19 09:50:53 +00:00
/* create the master switch */
2013-07-19 16:30:22 +03:00
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 6 ) ;
2013-02-19 09:50:53 +00:00
priv - > master_switch = gtk_switch_new ( ) ;
2015-03-25 15:27:43 -04:00
atk_object_set_name ( ATK_OBJECT ( gtk_widget_get_accessible ( priv - > master_switch ) ) , _ ( " Sharing " ) ) ;
2013-07-19 16:30:22 +03:00
gtk_widget_set_valign ( priv - > master_switch , GTK_ALIGN_CENTER ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , priv - > master_switch , FALSE , FALSE , 4 ) ;
gtk_widget_show_all ( box ) ;
2013-02-19 09:50:53 +00:00
/* start the panel in the disabled state */
gtk_switch_set_active ( GTK_SWITCH ( priv - > master_switch ) , FALSE ) ;
gtk_widget_set_sensitive ( WID ( " main-list-box " ) , FALSE ) ;
g_signal_connect ( priv - > master_switch , " notify::active " ,
G_CALLBACK ( cc_sharing_panel_master_switch_notify ) , self ) ;
2014-06-20 10:07:46 +02:00
self - > priv - > sharing_proxy = G_DBUS_PROXY ( gsd_sharing_proxy_new_for_bus_sync ( G_BUS_TYPE_SESSION ,
G_DBUS_PROXY_FLAGS_NONE ,
" org.gnome.SettingsDaemon.Sharing " ,
" /org/gnome/SettingsDaemon/Sharing " ,
NULL ,
& error ) ) ;
if ( ! self - > priv - > sharing_proxy ) {
g_warning ( " Failed to get sharing proxy: %s " , error - > message ) ;
g_error_free ( error ) ;
}
2013-02-19 09:50:53 +00:00
2013-01-14 17:58:44 +00:00
/* media sharing */
cc_sharing_panel_setup_media_sharing_dialog ( self ) ;
/* personal file sharing */
if ( cc_sharing_panel_check_schema_available ( self , FILE_SHARING_SCHEMA_ID ) )
cc_sharing_panel_setup_personal_file_sharing_dialog ( self ) ;
else
gtk_widget_hide ( WID ( " personal-file-sharing-button " ) ) ;
/* remote login */
cc_sharing_panel_setup_remote_login_dialog ( self ) ;
/* screen sharing */
if ( cc_sharing_panel_check_schema_available ( self , VINO_SCHEMA_ID ) )
cc_sharing_panel_setup_screen_sharing_dialog ( self ) ;
else
gtk_widget_hide ( WID ( " screen-sharing-button " ) ) ;
2013-01-29 16:23:17 +00:00
/* make sure the hostname entry isn't focused by default */
g_signal_connect_swapped ( self , " map " , G_CALLBACK ( gtk_widget_grab_focus ) ,
WID ( " main-list-box " ) ) ;
2013-01-14 17:58:44 +00:00
}
CcSharingPanel *
cc_sharing_panel_new ( void )
{
return g_object_new ( CC_TYPE_SHARING_PANEL , NULL ) ;
}