Ejemplo n.º 1
0
void
compare3(GtkAction* action, GtkWidget* window) {
  GList* files = g_list_first((GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::compare3"));
  gchar* f1 = 0;
  gchar* f2 = 0;
  gchar* f3 = 0;
  gchar* uri;

  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f1 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);
  files = g_list_next(files);
  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f2 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);
  files = g_list_next(files);
  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f3 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);

  diff3(f1, f2, f3);
  g_free(f1);
  g_free(f2);
  g_free(f3);
}
Ejemplo n.º 2
0
void
compare3_to(GtkAction* action, GtkWidget* window) {
  GList* files = g_list_first((GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::compare_to"));
  GList* saved = (GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::saved");
  gchar* f1 = 0;
  gchar* f2 = 0;
  gchar* f3 = (gchar*)saved->data;
  gboolean keep_file = FALSE;
  gchar* uri;
  xdiff_ext_preferences* p = xdiff_ext_preferences_instance();
  
  g_object_get(G_OBJECT(p), "keep-files-in-list", &keep_file, NULL);
  
  g_object_unref(p);

  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f1 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);
  files = g_list_next(files);
  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f2 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);

  diff3(f1, f2, f3);

  g_free(f1);
  g_free(f2);
  
  if(!keep_file) {
    clear_queue(_saved);
  }
}
Ejemplo n.º 3
0
void
compare_later(GtkAction* action, GtkWidget* window) {
  GList* files = g_list_first((GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::save"));
    
  while(files) {
    gchar* uri;
    gchar* path;
    GList* link;

    uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
    path = g_filename_from_uri(uri, NULL, NULL);
    g_free(uri);
    
    link = g_queue_find_custom(_saved, path, (GCompareFunc)strcmp);
    
    if(link == NULL) {
      g_queue_push_head(_saved, path);
    } else {
      g_queue_unlink(_saved, link);
      g_queue_push_head_link(_saved, link);
    }
    // g_free(path) ???
    files = g_list_next(files);
  }
}
Ejemplo n.º 4
0
static GList *gtkhash_properties_get_pages(
#if IN_NAUTILUS_EXTENSION
	G_GNUC_UNUSED NautilusPropertyPageProvider *provider,
#elif IN_CAJA_EXTENSION
	G_GNUC_UNUSED CajaPropertyPageProvider *provider,
#elif IN_NEMO_EXTENSION
	G_GNUC_UNUSED NemoPropertyPageProvider *provider,
#elif IN_THUNAR_EXTENSION
	G_GNUC_UNUSED ThunarxPropertyPageProvider *provider,
#endif
	GList *files)
{
	// Only display page for a single file
	if (!files || files->next)
		return NULL;

#if IN_NAUTILUS_EXTENSION
	GFileType type = nautilus_file_info_get_file_type(files->data);
	char *uri = nautilus_file_info_get_uri(files->data);
#elif IN_CAJA_EXTENSION
	GFileType type = caja_file_info_get_file_type(files->data);
	char *uri = caja_file_info_get_uri(files->data);
#elif IN_NEMO_EXTENSION
	GFileType type = nemo_file_info_get_file_type(files->data);
	char *uri = nemo_file_info_get_uri(files->data);
#elif IN_THUNAR_EXTENSION
	GFileInfo *info = thunarx_file_info_get_file_info(files->data);
	GFileType type = g_file_info_get_file_type(info);
	g_object_unref(info);

	char *uri = thunarx_file_info_get_uri(files->data);
#endif

	// Only display page for regular files
	if (type != G_FILE_TYPE_REGULAR)
		return NULL;

	struct page_s *page = gtkhash_properties_new_page(uri);
	if (!page)
		return NULL;

#if IN_NAUTILUS_EXTENSION
	NautilusPropertyPage *ppage = nautilus_property_page_new(
		"GtkHash::properties", gtk_label_new(_("Digests")), page->box);
#elif IN_CAJA_EXTENSION
	CajaPropertyPage *ppage = caja_property_page_new(
		"GtkHash::properties", gtk_label_new(_("Digests")), page->box);
#elif IN_NEMO_EXTENSION
	NemoPropertyPage *ppage = nemo_property_page_new(
		"GtkHash::properties", gtk_label_new(_("Digests")), page->box);
#elif IN_THUNAR_EXTENSION
	GtkWidget *ppage = thunarx_property_page_new(_("Digests"));
	gtk_container_add(GTK_CONTAINER(ppage), page->box);
#endif

	GList *pages = g_list_append(NULL, ppage);

	return pages;
}
Ejemplo n.º 5
0
static GList*
get_folder_actions(ThunarxMenuProvider* provider, GtkWidget* window, ThunarxFileInfo* folder) {
  GList* actions = 0;
  gchar* scheme;

  scheme = thunarx_file_info_get_uri_scheme(folder);
  if(strncmp(scheme, "file", 4) == 0) {
    GList* files = g_list_append(0, folder);
    GtkAction* action = gtk_action_new("xdiff-ext::save", _("Compare later"), _("Select file for comparison"), "diff_later");
    g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_later), window);
    g_object_set_data_full(G_OBJECT(action), "xdiff-ext::save", thunarx_file_info_list_copy(files), (GDestroyNotify)thunarx_file_info_list_free);
    actions = g_list_append(actions, action);
    
    if(!g_queue_is_empty(_saved)) {
      GString* caption = g_string_new("");
      GString* hint = g_string_new("");
      GList* head = g_queue_peek_head_link(_saved);
      gchar* head_file = (gchar*)head->data;
      gchar* uri;
      gchar* path;

      uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
      path = g_filename_from_uri(uri, NULL, NULL);
      g_free(uri);
      
      g_string_printf(caption, _("Compare to '%s'"), head_file);
      g_string_printf(hint, _("Compare '%s' and '%s'"), path, head_file);
      
      action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "diff_with");
      g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_to), window);
      g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files), (GDestroyNotify)thunarx_file_info_list_free);
      g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
      actions = g_list_append(actions, action);
      
      g_string_free(caption, TRUE);
      g_string_free(hint, TRUE);
    }
    
    g_list_free(files);
  }

  g_free(scheme);

  return actions;
}
Ejemplo n.º 6
0
static void
thunar_uca_provider_activated (ThunarUcaProvider *uca_provider,
                               GtkAction         *action)
{
  GtkTreeRowReference *row;
  ThunarUcaContext    *uca_context;
  GtkTreePath         *path;
  GtkTreeIter          iter;
  GtkWidget           *dialog;
  GtkWidget           *window;
  gboolean             succeed;
  GSource             *source;
  GError              *error = NULL;
  GList               *files;
  gchar              **argv;
  gchar               *working_directory = NULL;
  gchar               *filename;
  gchar               *label;
  gchar               *uri;
  gint                 argc;
  gint                 pid;

  g_return_if_fail (THUNAR_UCA_IS_PROVIDER (uca_provider));
  g_return_if_fail (GTK_IS_ACTION (action));

  /* check if the row reference is still valid */
  row = g_object_get_qdata (G_OBJECT (action), thunar_uca_row_quark);
  if (G_UNLIKELY (!gtk_tree_row_reference_valid (row)))
    return;

  /* determine the iterator for the item */
  path = gtk_tree_row_reference_get_path (row);
  gtk_tree_model_get_iter (GTK_TREE_MODEL (uca_provider->model), &iter, path);
  gtk_tree_path_free (path);

  /* determine the files and the window for the action */
  uca_context = g_object_get_qdata (G_OBJECT (action), thunar_uca_context_quark);
  window = thunar_uca_context_get_window (uca_context);
  files = thunar_uca_context_get_files (uca_context);

  /* determine the argc/argv for the item */
  succeed = thunar_uca_model_parse_argv (uca_provider->model, &iter, files, &argc, &argv, &error);
  if (G_LIKELY (succeed))
    {
      /* determine the working from the first file */
      if (G_LIKELY (files != NULL))
        {
          /* determine the filename of the first selected file */
          uri = thunarx_file_info_get_uri (files->data);
          filename = g_filename_from_uri (uri, NULL, NULL);
          if (G_LIKELY (filename != NULL))
            {
              /* if this is a folder action, we just use the filename as working directory */
              if (g_object_get_qdata (G_OBJECT (action), thunar_uca_folder_quark) != NULL)
                {
                  working_directory = filename;
                  filename = NULL;
                }
              else
                {
                  working_directory = g_path_get_dirname (filename);
                }
            }
          g_free (filename);
          g_free (uri);
        }

      /* spawn the command on the window's screen */
      succeed = gdk_spawn_on_screen (gtk_widget_get_screen (GTK_WIDGET (window)), working_directory,
                                     argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
                                     NULL, NULL, &pid, &error);

      /* check if we succeed */
      if (G_LIKELY (succeed))
        {
          /* check if we already have a child watch */
          if (G_UNLIKELY (uca_provider->child_watch_id >= 0))
            {
              /* reset the callback function to g_spawn_close_pid() so the plugin can be
               * safely unloaded and the child will still not become a zombie afterwards.
               */
              source = g_main_context_find_source_by_id (NULL, uca_provider->child_watch_id);
              g_source_set_callback (source, (GSourceFunc) g_spawn_close_pid, NULL, NULL);
            }

          /* schedule the new child watch */
          uca_provider->child_watch_id = g_child_watch_add_full (G_PRIORITY_LOW, pid, thunar_uca_provider_child_watch,
                                                                 uca_provider, thunar_uca_provider_child_watch_destroy);

          /* take over ownership of the working directory as child watch path */
          uca_provider->child_watch_path = working_directory;
          working_directory = NULL;
        }

      /* cleanup */
      g_free (working_directory);
      g_strfreev (argv);
    }

  /* present error message to the user */
  if (G_UNLIKELY (!succeed))
    {
      g_object_get (G_OBJECT (action), "label", &label, NULL);
      dialog = gtk_message_dialog_new ((GtkWindow *) window,
                                       GTK_DIALOG_DESTROY_WITH_PARENT
                                       | GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       _("Failed to launch action \"%s\"."), label);
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
      gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
      g_error_free (error);
      g_free (label);
    }
}
Ejemplo n.º 7
0
static void
thunar_uca_provider_activated (ThunarUcaProvider *uca_provider,
                               GtkAction         *action)
{
  GtkTreeRowReference *row;
  ThunarUcaContext    *uca_context;
  GtkTreePath         *path;
  GtkTreeIter          iter;
  GtkWidget           *dialog;
  GtkWidget           *window;
  gboolean             succeed;
  GError              *error = NULL;
  GList               *files;
  gchar              **argv;
  gchar               *working_directory = NULL;
  gchar               *filename;
  gchar               *label;
  gchar               *uri;
  gint                 argc;
  gchar               *icon_name = NULL;
  gboolean             startup_notify;
  GClosure            *child_watch;

  g_return_if_fail (THUNAR_UCA_IS_PROVIDER (uca_provider));
  g_return_if_fail (GTK_IS_ACTION (action));

  /* check if the row reference is still valid */
  row = g_object_get_qdata (G_OBJECT (action), thunar_uca_row_quark);
  if (G_UNLIKELY (!gtk_tree_row_reference_valid (row)))
    return;

  /* determine the iterator for the item */
  path = gtk_tree_row_reference_get_path (row);
  gtk_tree_model_get_iter (GTK_TREE_MODEL (uca_provider->model), &iter, path);
  gtk_tree_path_free (path);

  /* determine the files and the window for the action */
  uca_context = g_object_get_qdata (G_OBJECT (action), thunar_uca_context_quark);
  window = thunar_uca_context_get_window (uca_context);
  files = thunar_uca_context_get_files (uca_context);

  /* determine the argc/argv for the item */
  succeed = thunar_uca_model_parse_argv (uca_provider->model, &iter, files, &argc, &argv, &error);
  if (G_LIKELY (succeed))
    {
      /* get the icon name and whether startup notification is active */
      gtk_tree_model_get (GTK_TREE_MODEL (uca_provider->model), &iter,
                          THUNAR_UCA_MODEL_COLUMN_ICON, &icon_name,
                          THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY, &startup_notify,
                          -1);

      /* determine the working from the first file */
      if (G_LIKELY (files != NULL))
        {
          /* determine the filename of the first selected file */
          uri = thunarx_file_info_get_uri (files->data);
          filename = g_filename_from_uri (uri, NULL, NULL);
          if (G_LIKELY (filename != NULL))
            {
              /* if this is a folder action, we just use the filename as working directory */
              if (g_object_get_qdata (G_OBJECT (action), thunar_uca_folder_quark) != NULL)
                {
                  working_directory = filename;
                  filename = NULL;
                }
              else
                {
                  working_directory = g_path_get_dirname (filename);
                }
            }
          g_free (filename);
          g_free (uri);
        }

      /* build closre for child watch */
      child_watch = g_cclosure_new_swap (G_CALLBACK (thunar_uca_provider_child_watch),
                                         uca_provider, thunar_uca_provider_child_watch_destroy);
      g_closure_ref (child_watch);
      g_closure_sink (child_watch);

      /* spawn the command on the window's screen */
      succeed = xfce_spawn_on_screen_with_child_watch (gtk_widget_get_screen (GTK_WIDGET (window)),
                                                       working_directory, argv, NULL,
                                                       G_SPAWN_SEARCH_PATH,
                                                       startup_notify,
                                                       gtk_get_current_event_time (),
                                                       icon_name,
                                                       child_watch,
                                                       &error);

      /* check if we succeed */
      if (G_LIKELY (succeed))
        {
          /* release existing child watch */
          thunar_uca_provider_child_watch_destroy (uca_provider, NULL);

          /* set new closure */
          uca_provider->child_watch = child_watch;

          /* take over ownership of the working directory as child watch path */
          uca_provider->child_watch_path = working_directory;
          working_directory = NULL;
        }
      else
        {
          /* spawn failed, release watch */
          g_closure_unref (child_watch);
        }

      /* cleanup */
      g_free (working_directory);
      g_strfreev (argv);
      g_free (icon_name);
    }

  /* present error message to the user */
  if (G_UNLIKELY (!succeed))
    {
      g_object_get (G_OBJECT (action), "label", &label, NULL);
      dialog = gtk_message_dialog_new ((GtkWindow *) window,
                                       GTK_DIALOG_DESTROY_WITH_PARENT
                                       | GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       _("Failed to launch action \"%s\"."), label);
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
      gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
      g_error_free (error);
      g_free (label);
    }
}
Ejemplo n.º 8
0
static void
thunar_apr_desktop_page_save (ThunarAprDesktopPage *desktop_page,
                              GtkWidget            *widget)
{
    GtkWidget *toplevel;
    GtkWidget *message;
    GKeyFile  *key_file;
    GError    *error = NULL;
    gchar     *filename;
    gchar     *data;
    gchar     *uri;
    gsize      data_length;
    FILE      *fp;

    /* verify that we still have a valid file */
    if (THUNAR_APR_ABSTRACT_PAGE (desktop_page)->file == NULL)
        return;

    /* determine the local path to the file */
    uri = thunarx_file_info_get_uri (THUNAR_APR_ABSTRACT_PAGE (desktop_page)->file);
    filename = g_filename_from_uri (uri, NULL, NULL);
    g_free (uri);

    /* verify that we have a valid local path */
    if (G_UNLIKELY (filename == NULL))
        return;

    /* allocate the key file resources */
    key_file = g_key_file_new ();

    /* try to parse the key file */
    if (g_key_file_load_from_file (key_file, filename, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error))
    {
        /* save the widget changes to the key file */
        thunar_apr_desktop_page_save_widget (desktop_page, widget, key_file);

        /* give empty desktop files a type */
        if (!g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP,
                                 G_KEY_FILE_DESKTOP_KEY_TYPE, NULL))
        {
            g_key_file_set_string (key_file,
                                   G_KEY_FILE_DESKTOP_GROUP,
                                   G_KEY_FILE_DESKTOP_KEY_TYPE,
                                   "Application");
        }

        /* determine the content of the key file */
        data = g_key_file_to_data (key_file, &data_length, &error);
        if (G_LIKELY (data_length > 0))
        {
            /* try to save the key file content to disk */
            fp = fopen (filename, "w");
            if (G_LIKELY (fp != NULL))
            {
                if (fwrite (data, data_length, 1, fp) != 1)
                    error = g_error_new_literal (G_FILE_ERROR, g_file_error_from_errno (errno), g_strerror (errno));
                fclose (fp);
            }
            else
            {
                error = g_error_new_literal (G_FILE_ERROR, g_file_error_from_errno (errno), g_strerror (errno));
            }
        }

        /* cleanup */
        g_free (data);
    }

    /* check if we succeed */
    if (G_UNLIKELY (error != NULL))
    {
        /* display an error dialog to the user */
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (desktop_page));
        message = gtk_message_dialog_new ((GtkWindow *) toplevel,
                                          GTK_DIALOG_DESTROY_WITH_PARENT
                                          | GTK_DIALOG_MODAL,
                                          GTK_MESSAGE_ERROR,
                                          GTK_BUTTONS_CLOSE,
                                          _("Failed to save \"%s\"."), filename);
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s.", error->message);
        gtk_dialog_run (GTK_DIALOG (message));
        gtk_widget_destroy (message);
        g_error_free (error);
    }

    /* cleanup */
    g_key_file_free (key_file);
    g_free (filename);
}
Ejemplo n.º 9
0
static void
thunar_apr_desktop_page_file_changed (ThunarAprAbstractPage *abstract_page,
                                      ThunarxFileInfo       *file)
{
    ThunarAprDesktopPage *desktop_page = THUNAR_APR_DESKTOP_PAGE (abstract_page);
    GKeyFile             *key_file;
    gboolean              writable;
    gboolean              enabled;
    GError               *error = NULL;
    gchar                *filename;
    gchar                *value;
    gchar                *type;
    gchar                *uri;

    /* allocate the key file memory */
    key_file = g_key_file_new ();

    /* determine the local path to the file */
    uri = thunarx_file_info_get_uri (file);
    filename = g_filename_from_uri (uri, NULL, NULL);
    g_free (uri);

    /* try to load the file contents */
    if (filename != NULL && g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL))
    {
        /* determine the type of the .desktop file (default to "Application") */
        type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Type", NULL);
        if (G_UNLIKELY (type == NULL))
            type = g_strdup ("Application");

        /* change page title depending on the type */
        if (strcmp (type, "Application") == 0)
            thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), _("Launcher"));
        else if (strcmp (type, "Link") == 0)
            thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), _("Link"));
        else
            thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), type);

        /* update the "Description" entry */
        value = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "GenericName", NULL, NULL);
        if (!exo_str_is_equal (value, desktop_page->description_text))
        {
            /* update the entry */
            gtk_entry_set_text (GTK_ENTRY (desktop_page->description_entry), (value != NULL) ? value : "");

            /* update the saved value */
            g_free (desktop_page->description_text);
            desktop_page->description_text = value;
        }
        else
        {
            g_free (value);
        }

        /* update the "Comment" entry */
        value = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Comment", NULL, NULL);
        if (!exo_str_is_equal (value, desktop_page->comment_text))
        {
            /* update the entry */
            gtk_entry_set_text (GTK_ENTRY (desktop_page->comment_entry), (value != NULL) ? value : "");

            /* update the saved value */
            g_free (desktop_page->comment_text);
            desktop_page->comment_text = value;
        }
        else
        {
            g_free (value);
        }

        /* update the type dependant entries */
        if (strcmp (type, "Application") == 0)
        {
            /* update the "Command" entry */
            value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Exec", NULL);
            if (!exo_str_is_equal (value, desktop_page->command_text))
            {
                /* update the entry */
                gtk_entry_set_text (GTK_ENTRY (desktop_page->command_entry), (value != NULL) ? value : "");

                /* update the saved value */
                g_free (desktop_page->command_text);
                desktop_page->command_text = value;
            }
            else
            {
                g_free (value);
            }

            /* update the "Path" entry */
            value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Path", NULL);
            if (!exo_str_is_equal (value, desktop_page->path_text))
            {
                /* update the entry */
                gtk_entry_set_text (GTK_ENTRY (desktop_page->path_entry), (value != NULL) ? value : "");

                /* update the saved value */
                g_free (desktop_page->path_text);
                desktop_page->path_text = value;
            }
            else
            {
                g_free (value);
            }

            /* update the "Use startup notification" button */
            enabled = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, "StartupNotify", &error);
            g_signal_handlers_block_by_func (G_OBJECT (desktop_page->snotify_button), thunar_apr_desktop_page_toggled, desktop_page);
            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (desktop_page->snotify_button), (error == NULL && enabled));
            g_signal_handlers_unblock_by_func (G_OBJECT (desktop_page->snotify_button), thunar_apr_desktop_page_toggled, desktop_page);
            g_clear_error (&error);

            /* update the "Run in terminal" button */
            enabled = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, "Terminal", &error);
            g_signal_handlers_block_by_func (G_OBJECT (desktop_page->terminal_button), thunar_apr_desktop_page_toggled, desktop_page);
            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (desktop_page->terminal_button), (error == NULL && enabled));
            g_signal_handlers_unblock_by_func (G_OBJECT (desktop_page->terminal_button), thunar_apr_desktop_page_toggled, desktop_page);
            g_clear_error (&error);

            /* update visibility of the specific widgets */
            gtk_widget_show (desktop_page->command_entry);
            gtk_widget_show (desktop_page->path_entry);
            gtk_widget_hide (desktop_page->url_entry);
            gtk_widget_show (desktop_page->snotify_button);
            gtk_widget_show (desktop_page->terminal_button);
        }
        else if (strcmp (type, "Link") == 0)
        {
            /* update the "URL" entry */
            value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "URL", NULL);
            if (!exo_str_is_equal (value, desktop_page->url_text))
            {
                /* update the entry */
                gtk_entry_set_text (GTK_ENTRY (desktop_page->url_entry), (value != NULL) ? value : "");

                /* update the saved value */
                g_free (desktop_page->url_text);
                desktop_page->url_text = value;
            }
            else
            {
                g_free (value);
            }

            /* update visibility of the specific widgets */
            gtk_widget_hide (desktop_page->command_entry);
            gtk_widget_hide (desktop_page->path_entry);
            gtk_widget_show (desktop_page->url_entry);
            gtk_widget_hide (desktop_page->snotify_button);
            gtk_widget_hide (desktop_page->terminal_button);
        }
        else
        {
            /* hide the specific widgets */
            gtk_widget_hide (desktop_page->command_entry);
            gtk_widget_hide (desktop_page->path_entry);
            gtk_widget_hide (desktop_page->url_entry);
            gtk_widget_hide (desktop_page->snotify_button);
            gtk_widget_hide (desktop_page->terminal_button);
        }

        /* check if the file is writable... */
        writable = (g_access (filename, W_OK) == 0);

        /* ...and update the editability of the entries */
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->description_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->command_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->path_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->url_entry), writable);
        gtk_editable_set_editable (GTK_EDITABLE (desktop_page->comment_entry), writable);
        gtk_widget_set_sensitive (desktop_page->snotify_button, writable);
        gtk_widget_set_sensitive (desktop_page->terminal_button, writable);

        /* cleanup */
        g_free (type);
    }
    else
    {
        /* reset page title */
        thunarx_property_page_set_label (THUNARX_PROPERTY_PAGE (desktop_page), _("Unknown"));

        /* hide all widgets */
        gtk_widget_hide (desktop_page->description_entry);
        gtk_widget_hide (desktop_page->command_entry);
        gtk_widget_hide (desktop_page->path_entry);
        gtk_widget_hide (desktop_page->url_entry);
        gtk_widget_hide (desktop_page->comment_entry);
        gtk_widget_hide (desktop_page->snotify_button);
        gtk_widget_hide (desktop_page->terminal_button);
    }

    /* cleanup */
    g_key_file_free (key_file);
    g_free (filename);
}
Ejemplo n.º 10
0
static GList*
get_file_actions(ThunarxMenuProvider* provider, GtkWidget* window, GList* files) {
  GList* actions = 0;
  
  if(files != 0) {
    GtkIconTheme* theme = gtk_icon_theme_get_default();
    guint n = g_list_length(files);
    gchar* three_way_compare_command;
    xdiff_ext_preferences* p = xdiff_ext_preferences_instance();

    g_object_get(G_OBJECT(p), "three-way-compare-command", &three_way_compare_command, NULL);

    g_object_unref(p);
     
    GList* scan = files;
    gboolean go = TRUE;
    
    while(scan && go) {
      gchar* scheme;

      scheme = thunarx_file_info_get_uri_scheme((ThunarxFileInfo*)(scan->data));
      go = strncmp(scheme, "file", 4) == 0;
      g_free(scheme);
      
      scan = g_list_next(scan);
    }
    
    if(go) {
      GtkAction* action = gtk_action_new("xdiff-ext::save", _("Compare later"), _("Select file for comparison"), DIFF_EXT_DATA_DIR"/icons/hicolor/16x16/actions/diff_later.png");
      g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_later), window);
      g_object_set_data_full(G_OBJECT(action), "xdiff-ext::save", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
      actions = g_list_append(actions, action);
      
      if(n == 1) {
        if(!g_queue_is_empty(_saved)) {
          GString* caption = g_string_new("");
          GString* hint = g_string_new("");
          GList* head = g_queue_peek_head_link(_saved);
          gchar* head_file = (gchar*)head->data;
          ThunarVfsInfo* vfs_info = NULL;
          ThunarVfsPath* vfs_path = NULL;
          const gchar* icon_name;
          
          gchar* uri;
          gchar* path;

          uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
          path = g_filename_from_uri(uri, NULL, NULL);
          g_free(uri);
          
          g_string_printf(caption,_("Compare to '%s'"), head_file);
          g_string_printf(hint, _("Compare '%s' and '%s'"), path, head_file);
          
          vfs_path = thunar_vfs_path_new(head_file, NULL);
          vfs_info = thunar_vfs_info_new_for_path(vfs_path, NULL);
          icon_name = thunar_vfs_info_get_custom_icon(vfs_info);
          if(icon_name == NULL) {
            icon_name = thunar_vfs_mime_info_lookup_icon_name(vfs_info->mime_info, theme);
          }
          
          g_message("icon name: '%s'", icon_name);
          thunar_vfs_path_unref(vfs_path);
          thunar_vfs_info_unref(vfs_info);
          
          action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "gaim.png");
          g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_to), window);
          g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
          g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
          actions = g_list_append(actions, action);
          
          if(_saved->length > 1) {
            add_compare_to_menu(actions, window, files, _("Compare to"), make_hint, G_CALLBACK(compare_to), path);
          }
          
          g_string_free(caption, TRUE);
          g_string_free(hint, TRUE);
        }
      } else if(n == 2) {
        GtkAction* action = gtk_action_new("xdiff-ext::compare", _("Compare"), _("Compare selected files"), "diff");
        g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare), window);
        g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
        actions = g_list_append(actions, action);

        if(strcmp("", three_way_compare_command) != 0) {
          if(!g_queue_is_empty(_saved)) {
            GString* caption = g_string_new("");
            GString* hint = g_string_new("");
            GList* head = g_queue_peek_head_link(_saved);
            gchar* head_file = (gchar*)head->data;
            gchar* uri;
            gchar* path1;
            gchar* path2;

            uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
            path1 = g_filename_from_uri(uri, NULL, NULL);
            g_free(uri);
            files = g_list_next(files);
            uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
            path2 = g_filename_from_uri(uri, NULL, NULL);
            g_free(uri);
            
            g_string_printf(caption, _("3-way compare to '%s'"), head_file);
            g_string_printf(hint, _("3-way compare '%s', '%s' and '%s'"), path1, path2, head_file);
            
            action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "diff3_with");
            g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3_to), window);
            g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
            g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
            actions = g_list_append(actions, action);

            if(_saved->length > 1) {
              add_compare_to_menu(actions, window, files, _("3-way compare to"), make_hint3, G_CALLBACK(compare3_to), path1, path2);
            }
            
            g_string_free(caption, TRUE);
            g_string_free(hint, TRUE);
          }
        }
      } else if(n == 3) {
        if(strcmp("", three_way_compare_command) != 0) {
          GtkAction* action = gtk_action_new("xdiff-ext::compare3", _("3-way Compare"), _("Compare selected files"), "diff3");
          g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3), window);
          g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare3", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
          actions = g_list_append(actions, action);
        }
      }
    }
    
    g_free(three_way_compare_command);
  }
          
  return actions;
}
Ejemplo n.º 11
0
static void
twp_action_set_wallpaper (GtkAction *action,
                          gpointer   user_data)
{
  ThunarxFileInfo *file_info = user_data;
  GdkDisplay      *display = gdk_display_get_default();
  gint             n_screens = gdk_display_get_n_screens (display);
  gint             screen_nr = 0;
  gint             n_monitors;
  gint             monitor_nr = 0;
  GdkScreen       *screen;
  gchar           *image_path_prop;
  gchar           *image_show_prop;
  gchar           *image_style_prop;
  gchar           *file_uri;
  gchar           *escaped_file_name;
  gchar           *file_name = NULL;
  gchar           *hostname = NULL;
  gchar           *command;

  if (desktop_type != DESKTOP_TYPE_NONE)
    {
      file_uri = thunarx_file_info_get_uri (file_info);
      file_name = g_filename_from_uri (file_uri, &hostname, NULL);
      if (hostname != NULL)
        {
          g_free (hostname);
          g_free (file_uri);
          g_free (file_name);

          return;
        }
      if (n_screens > 1)
        screen = gdk_display_get_default_screen (display);
      else
        screen = gdk_display_get_screen (display, 0);

      n_monitors = gdk_screen_get_n_monitors (screen);
      if (n_monitors > 1)
        {
          /* ? */
        }
      g_free(file_uri);
    }

  escaped_file_name = g_shell_quote (file_name);

  switch (desktop_type)
    {
      case DESKTOP_TYPE_XFCE:
        g_debug ("set on xfce");
        image_path_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-path", screen_nr, monitor_nr);
        image_show_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-show", screen_nr, monitor_nr);
        image_style_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-style", screen_nr, monitor_nr);

        command = g_strdup_printf ("xfconf-query -c xfce4-desktop -p %s --create -t string -s %s", image_path_prop, escaped_file_name);
        g_spawn_command_line_async (command, NULL);
        g_free (command);

        command = g_strdup_printf ("xfconf-query -c xfce4-desktop -p %s --create -t bool -s true", image_show_prop);
        g_spawn_command_line_async (command, NULL);
        g_free (command);

        command = g_strdup_printf ("xfconf-query -c xfce4-desktop -p %s --create -t int -s 0", image_style_prop);
        g_spawn_command_line_async (command, NULL);
        g_free (command);

        g_free(image_path_prop);
        g_free(image_show_prop);
        g_free(image_style_prop);
        break;

      case DESKTOP_TYPE_NAUTILUS:
        g_debug ("set on gnome");
        image_path_prop = g_strdup_printf("/desktop/gnome/background/picture_filename");
        image_show_prop = g_strdup_printf("/desktop/gnome/background/draw_background");

        command = g_strdup_printf ("gconftool-2 %s --set %s--type string", image_path_prop, escaped_file_name);
        g_spawn_command_line_async (command, NULL);
        g_free (command);


        command = g_strdup_printf ("gconftool-2 %s --set true --type boolean", image_show_prop);
        g_spawn_command_line_async (command, NULL);
        g_free (command);

        g_free(image_path_prop);
        g_free(image_show_prop);
        break;

      default:
        return;
        break;
    }

  g_free (escaped_file_name);
  g_free(file_name);
}