static void
screenshot_dialog_response_cb (GtkDialog *d,
                               gint response_id,
                               gpointer user_data)
{
  ScreenshotApplication *self = user_data;

  switch (response_id)
    {
    case GTK_RESPONSE_HELP:
      screenshot_display_help (GTK_WINDOW (d));
      break;
    case GTK_RESPONSE_OK:
      /* update to the new URI */
      g_free (self->priv->save_uri);
      self->priv->save_uri = screenshot_dialog_get_uri (self->priv->dialog);
      screenshot_save_to_file (self);
      break;
    case SCREENSHOT_RESPONSE_COPY:
      screenshot_save_to_clipboard (self);
      break;
    default:
      gtk_widget_destroy (GTK_WIDGET (d));
      break;
    }
}
예제 #2
0
static void
save_callback (TransferResult result,
               char *error_message,
               gpointer data)
{
  ScreenshotDialog *dialog = data;
  GtkWidget *toplevel;
  
  toplevel = screenshot_dialog_get_toplevel (dialog);
  screenshot_dialog_set_busy (dialog, FALSE);

  if (result == TRANSFER_OK)
    {
      save_folder_to_gconf (dialog);
      set_recent_entry (dialog);
      gtk_widget_destroy (toplevel);
      
      /* we're done, stop the mainloop now */
      gtk_main_quit ();
    }
  else if (result == TRANSFER_OVERWRITE ||
           result == TRANSFER_CANCELLED)
    {
      /* user has canceled the overwrite dialog or the transfer itself, let him
       * choose another name.
       */
      screenshot_dialog_focus_entry (dialog);
    }
  else /* result == TRANSFER_ERROR */
    {
      /* we had an error, display a dialog to the user and let him choose
       * another name/location to save the screenshot.
       */
      GtkWidget *error_dialog;
      char *uri;
      
      uri = screenshot_dialog_get_uri (dialog);
      error_dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
                                       GTK_DIALOG_DESTROY_WITH_PARENT,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_OK,
                                       _("Error while saving screenshot"),
                                       NULL);
      /* translators: first %s is the file path, second %s is the VFS error */
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
                                                _("Impossible to save the screenshot "
                                                  "to %s.\n Error was %s.\n Please choose another "
                                                  "location and retry."), uri, error_message);
      gtk_widget_show (error_dialog);
      g_signal_connect (error_dialog,
                        "response",
                        G_CALLBACK (error_dialog_response_cb),
                        dialog);

      g_free (uri);
    }
      
}
예제 #3
0
static void
screenshot_dialog_response_cb (GtkDialog *d,
                               gint response_id,
                               ScreenshotDialog *dialog)
{
  char *uri;

  if (response_id == GTK_RESPONSE_HELP)
    {
      display_help (GTK_WINDOW (d));
    }
  else if (response_id == GTK_RESPONSE_OK)
    {
      uri = screenshot_dialog_get_uri (dialog);
      if (temporary_file == NULL)
        {
          save_immediately = TRUE;
          screenshot_dialog_set_busy (dialog, TRUE);
        }
      else
        {
          /* we've saved the temporary file, lets try to copy it to the
           * correct location.
           */
          try_to_save (dialog, uri);
        }
      g_free (uri);
    }
  else if (response_id == SCREENSHOT_RESPONSE_COPY)
    {
      GtkClipboard *clipboard;
      GdkPixbuf    *screenshot;

      clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (d)),
                                                 GDK_SELECTION_CLIPBOARD);
      screenshot = screenshot_dialog_get_screenshot (dialog);
      gtk_clipboard_set_image (clipboard, screenshot);
    }
  else /* dialog was canceled */
    {
      gtk_widget_destroy (GTK_WIDGET (d));
      gtk_main_quit ();
    }
}
예제 #4
0
static void
try_to_save (ScreenshotDialog *dialog)
{
  gchar *target_uri;
  GFile *target_file;

  screenshot_dialog_set_busy (dialog, TRUE);

  target_uri = screenshot_dialog_get_uri (dialog);
  target_file = g_file_new_for_uri (target_uri);

  g_file_create_async (target_file,
                       G_FILE_CREATE_NONE,
                       G_PRIORITY_DEFAULT,
                       NULL,
                       save_file_create_ready_cb, dialog);

  g_object_unref (target_file);
  g_free (target_uri);
}
예제 #5
0
static void
set_recent_entry (ScreenshotDialog *dialog)
{
  char *uri, *app_exec = NULL;
  GtkRecentManager *recent;
  GtkRecentData recent_data;
  GAppInfo *app;
  const char *exec_name = NULL;
  static char * groups[2] = { "Graphics", NULL };

  app = g_app_info_get_default_for_type ("image/png", TRUE);

  if (!app) {
    /* return early, as this would be an useless recent entry anyway. */
    return;
  }

  uri = screenshot_dialog_get_uri (dialog);
  recent = gtk_recent_manager_get_default ();
  
  exec_name = g_app_info_get_executable (app);
  app_exec = g_strjoin (" ", exec_name, "%u", NULL);

  recent_data.display_name = NULL;
  recent_data.description = NULL;
  recent_data.mime_type = "image/png";
  recent_data.app_name = "MATE Screenshot";
  recent_data.app_exec = app_exec;
  recent_data.groups = groups;
  recent_data.is_private = FALSE;

  gtk_recent_manager_add_full (recent, uri, &recent_data);

  g_object_unref (app);
  g_free (app_exec);
  g_free (uri);
}