summaryrefslogtreecommitdiff
path: root/src/nautilus-sendto-command.c
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2008-04-23 14:51:53 +0000
committerBastien Nocera <hadess@src.gnome.org>2008-04-23 14:51:53 +0000
commit64bc241a0a51c46c9011087cbbcf9a8af288095b (patch)
tree8afc9e55b945a6f802561f321a6cfc37923515c2 /src/nautilus-sendto-command.c
parent7219edb32307b90e559cde59749a851be47ad999 (diff)
downloadnautilus-sendto-64bc241a0a51c46c9011087cbbcf9a8af288095b.tar.gz
Make the send button unsensitive when packing in a file is enabled and
2008-04-23 Bastien Nocera <hadess@hadess.net> * src/nautilus-sendto-command.c (pack_files), (send_button_cb), (toggle_pack_check), (pack_entry_changed_cb), (nautilus_sendto_create_ui): Make the send button unsensitive when packing in a file is enabled and there's no filename for the archive, remove a really crappy string and a useful dialogue (Closes: #521999) svn path=/trunk/; revision=322
Diffstat (limited to 'src/nautilus-sendto-command.c')
-rw-r--r--src/nautilus-sendto-command.c182
1 files changed, 102 insertions, 80 deletions
diff --git a/src/nautilus-sendto-command.c b/src/nautilus-sendto-command.c
index cc55ea3..59a2fa9 100644
--- a/src/nautilus-sendto-command.c
+++ b/src/nautilus-sendto-command.c
@@ -177,82 +177,71 @@ static char *
pack_files (NS_ui *ui)
{
char *file_roller_cmd;
- GtkWidget *error_dialog;
+ const char *filename;
+ GList *l;
+ GString *cmd, *tmp;
+ char *pack_type, *tmp_dir, *tmp_work_dir, *packed_file;
file_roller_cmd = g_find_program_in_path ("file-roller");
-
- if (strlen (gtk_entry_get_text(GTK_ENTRY(ui->pack_entry))) != 0)
- {
- GList *l;
- GString *cmd, *tmp;
- char *pack_type, *tmp_dir, *tmp_work_dir, *packed_file;
+ filename = gtk_entry_get_text(GTK_ENTRY(ui->pack_entry));
- tmp_dir = g_strdup_printf ("%s/nautilus-sendto-%s",
+ g_assert (filename != NULL && *filename != '\0');
+
+ tmp_dir = g_strdup_printf ("%s/nautilus-sendto-%s",
g_get_tmp_dir(), g_get_user_name());
- g_mkdir (tmp_dir, 0700);
- tmp_work_dir = g_strdup_printf ("%s/nautilus-sendto-%s/%li",
- g_get_tmp_dir(), g_get_user_name(),
- time(NULL));
- g_mkdir (tmp_work_dir, 0700);
- g_free (tmp_dir);
-
- switch (gtk_combo_box_get_active (GTK_COMBO_BOX(ui->pack_combobox)))
- {
- case 0:
- pack_type = g_strdup (".zip");
- break;
- case 1:
- pack_type = g_strdup (".tar.gz");
- break;
- case 2:
- pack_type = g_strdup (".tar.bz2");
- break;
- default:
- pack_type = NULL;
- g_assert_not_reached ();
- }
-
- gconf_client_set_int(gconf_client,
- NAUTILUS_SENDTO_LAST_COMPRESS,
- gtk_combo_box_get_active(GTK_COMBO_BOX(ui->pack_combobox)),
- NULL);
+ g_mkdir (tmp_dir, 0700);
+ tmp_work_dir = g_strdup_printf ("%s/nautilus-sendto-%s/%li",
+ g_get_tmp_dir(), g_get_user_name(),
+ time(NULL));
+ g_mkdir (tmp_work_dir, 0700);
+ g_free (tmp_dir);
+
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX(ui->pack_combobox)))
+ {
+ case 0:
+ pack_type = g_strdup (".zip");
+ break;
+ case 1:
+ pack_type = g_strdup (".tar.gz");
+ break;
+ case 2:
+ pack_type = g_strdup (".tar.bz2");
+ break;
+ default:
+ pack_type = NULL;
+ g_assert_not_reached ();
+ }
- cmd = g_string_new ("");
- g_string_printf (cmd, "%s --add-to=\"%s/%s%s\"",
- file_roller_cmd, tmp_work_dir,
- gtk_entry_get_text (GTK_ENTRY(ui->pack_entry)),
- pack_type);
+ gconf_client_set_int(gconf_client,
+ NAUTILUS_SENDTO_LAST_COMPRESS,
+ gtk_combo_box_get_active(GTK_COMBO_BOX(ui->pack_combobox)),
+ NULL);
- /* file-roller doesn't understand URIs */
- for (l = file_list ; l; l=l->next){
- char *file;
+ cmd = g_string_new ("");
+ g_string_printf (cmd, "%s --add-to=\"%s/%s%s\"",
+ file_roller_cmd, tmp_work_dir,
+ filename,
+ pack_type);
- file = g_filename_from_uri (l->data, NULL, NULL);
- g_string_append_printf (cmd," \"%s\"", file);
- g_free (file);
- }
+ /* file-roller doesn't understand URIs */
+ for (l = file_list ; l; l=l->next){
+ char *file;
- g_spawn_command_line_sync (cmd->str, NULL, NULL, NULL, NULL);
- g_string_free (cmd, TRUE);
- tmp = g_string_new("");
- g_string_printf (tmp,"%s/%s%s", tmp_work_dir,
- gtk_entry_get_text (GTK_ENTRY(ui->pack_entry)),
- pack_type);
- g_free (tmp_work_dir);
- packed_file = g_filename_to_uri (tmp->str, NULL, NULL);
- g_string_free(tmp, TRUE);
- return packed_file;
- }else{
- error_dialog = gtk_message_dialog_new (GTK_WINDOW(ui->dialog),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("You don't insert the package name"));
- gtk_dialog_run (GTK_DIALOG (error_dialog));
- gtk_widget_destroy (error_dialog);
- return NULL;
+ file = g_filename_from_uri (l->data, NULL, NULL);
+ g_string_append_printf (cmd," \"%s\"", file);
+ g_free (file);
}
-
+
+ g_spawn_command_line_sync (cmd->str, NULL, NULL, NULL, NULL);
+ g_string_free (cmd, TRUE);
+ tmp = g_string_new("");
+ g_string_printf (tmp,"%s/%s%s", tmp_work_dir,
+ filename,
+ pack_type);
+ g_free (tmp_work_dir);
+ packed_file = g_filename_to_uri (tmp->str, NULL, NULL);
+ g_string_free(tmp, TRUE);
+ return packed_file;
}
static gboolean
@@ -276,8 +265,6 @@ send_button_cb (GtkWidget *widget, gpointer data)
GtkWidget *w;
gtk_widget_set_sensitive (ui->dialog, FALSE);
- while (gtk_events_pending ())
- gtk_main_iteration ();
p = (NstPlugin *) g_list_nth_data (plugin_list, option);
w = (GtkWidget *) g_list_nth_data (ui->contact_widgets, option);
@@ -314,7 +301,7 @@ send_button_cb (GtkWidget *widget, gpointer data)
if (force_user_to_compress){
f = pack_files (ui);
- if (f != NULL){
+ if (f != NULL) {
GList *packed_file = NULL;
packed_file = g_list_append (packed_file, f);
if (!p->info->send_files (p, w, packed_file)) {
@@ -322,13 +309,14 @@ send_button_cb (GtkWidget *widget, gpointer data)
return;
}
g_list_free (packed_file);
- }else{
+ } else {
+ gtk_widget_set_sensitive (ui->dialog, TRUE);
return;
}
}else{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui->pack_checkbutton))){
f = pack_files (ui);
- if (f != NULL){
+ if (f != NULL) {
GList *packed_file = NULL;
packed_file = g_list_append (packed_file, f);
if (!p->info->send_files (p, w, packed_file)) {
@@ -336,10 +324,11 @@ send_button_cb (GtkWidget *widget, gpointer data)
return;
}
g_list_free (packed_file);
- }else{
+ } else {
+ gtk_widget_set_sensitive (ui->dialog, TRUE);
return;
}
- }else{
+ } else {
if (!p->info->send_files (p, w, file_list)) {
g_list_foreach (file_list, (GFunc) g_free, NULL);
g_list_free (file_list);
@@ -370,15 +359,26 @@ send_if_no_pack_cb (GtkWidget *widget, gpointer data)
}
static void
-toggle_pack_check (GtkWidget *widget, gpointer data )
+toggle_pack_check (GtkWidget *widget, NS_ui *ui)
{
GtkToggleButton *t = GTK_TOGGLE_BUTTON (widget);
- NS_ui *ui_x = (NS_ui *) data ;
- gint toogle ;
+ gboolean enabled, send_enabled;
+
+ enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (t));
+ gtk_widget_set_sensitive (ui->pack_combobox, enabled);
+ gtk_widget_set_sensitive (ui->pack_entry, enabled);
- toogle = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (t));
- gtk_widget_set_sensitive (ui_x->pack_combobox, toogle);
- gtk_widget_set_sensitive (ui_x->pack_entry, toogle);
+ send_enabled = TRUE;
+
+ if (enabled) {
+ const char *filename;
+
+ filename = gtk_entry_get_text(GTK_ENTRY(ui->pack_entry));
+ if (filename == NULL || *filename == '\0')
+ send_enabled = FALSE;
+ }
+
+ gtk_widget_set_sensitive (ui->send_button, send_enabled);
}
static void
@@ -476,6 +476,26 @@ set_model_for_options_combobox (NS_ui *ui){
}
static void
+pack_entry_changed_cb (GObject *object,
+ GParamSpec *spec,
+ NS_ui *ui)
+{
+ gboolean send_enabled;
+
+ send_enabled = TRUE;
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui->pack_checkbutton))) {
+ const char *filename;
+
+ filename = gtk_entry_get_text(GTK_ENTRY(ui->pack_entry));
+ if (filename == NULL || *filename == '\0')
+ send_enabled = FALSE;
+ }
+
+ gtk_widget_set_sensitive (ui->send_button, send_enabled);
+}
+
+static void
nautilus_sendto_create_ui (void)
{
GladeXML *app;
@@ -544,6 +564,8 @@ nautilus_sendto_create_ui (void)
G_CALLBACK (send_button_cb), ui);
g_signal_connect (G_OBJECT (ui->pack_entry), "activate",
G_CALLBACK (send_button_cb), ui);
+ g_signal_connect (G_OBJECT (ui->pack_entry), "notify::text",
+ G_CALLBACK (pack_entry_changed_cb), ui);
if (force_user_to_compress == FALSE){
toggle = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui->pack_checkbutton));