Beispiel #1
0
static void
build_filename_ready_cb (GObject *source,
                         GAsyncResult *res,
                         gpointer user_data)
{
  GtkWidget *toplevel;
  ScreenshotDialog *dialog;
  GdkPixbuf *screenshot = user_data;
  gchar *save_uri;
  GError *error = NULL;

  save_uri = screenshot_build_filename_finish (res, &error);

  if (error != NULL)
    {
      g_critical ("Impossible to find a valid location to save the screenshot: %s",
                  error->message);
      g_error_free (error);

      exit(1);
    }

  dialog = screenshot_dialog_new (screenshot, save_uri);
  toplevel = screenshot_dialog_get_toplevel (dialog);
  gtk_widget_show (toplevel);
  
  g_signal_connect (toplevel,
                    "response",
                    G_CALLBACK (screenshot_dialog_response_cb),
                    dialog);

  g_free (save_uri);
}
static void
build_filename_ready_cb (GObject *source,
                         GAsyncResult *res,
                         gpointer user_data)
{
  ScreenshotApplication *self = user_data;
  GError *error = NULL;
  char *save_path;

  save_path = screenshot_build_filename_finish (res, &error);
  if (save_path != NULL)
    {
      GFile *file;

      file = g_file_new_for_path (save_path);
      g_free (save_path);

      self->priv->save_uri = g_file_get_uri (file);
      g_object_unref (file);
    }
  else
    self->priv->save_uri = NULL;

  /* now release the application */
  g_application_release (G_APPLICATION (self));

  if (error != NULL)
    {
      g_critical ("Impossible to find a valid location to save the screenshot: %s",
                  error->message);
      g_error_free (error);

      if (screenshot_config->interactive)
        screenshot_show_dialog (NULL,
                                GTK_MESSAGE_ERROR,
                                GTK_BUTTONS_OK,
                                _("Unable to capture a screenshot"),
                                _("Error creating file"));
      else
        {
          screenshot_play_sound_effect ("dialog-error", _("Unable to capture a screenshot"));
          if (screenshot_config->file != NULL)
            exit (EXIT_FAILURE);
        }

      return;
    }

  screenshot_play_sound_effect ("screen-capture", _("Screenshot taken"));

  if (!g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") || screenshot_config->interactive)
    {
      self->priv->dialog = screenshot_dialog_new (self->priv->screenshot, self->priv->save_uri);
      g_signal_connect (self->priv->dialog->dialog,
                        "response",
                        G_CALLBACK (screenshot_dialog_response_cb),
                        self);
    }
  else
    {
      g_application_hold (G_APPLICATION (self));
      screenshot_save_to_file (self);
    }
}