Exemple #1
0
static gchar *
ft_manager_format_progress_bytes_and_percentage (guint64 current,
                                                 guint64 total,
                                                 gdouble speed,
                                                 int *percentage)
{
  char *total_str, *current_str, *retval;
  char *speed_str = NULL;

  total_str = g_format_size_for_display (total);
  current_str = g_format_size_for_display (current);

  if (speed > 0)
    speed_str = g_format_size_for_display ((goffset) speed);

  /* translators: first %s is the currently processed size, second %s is
   * the total file size */
  retval = speed_str ?
    g_strdup_printf (_("%s of %s at %s/s"), current_str, total_str, speed_str) :
    g_strdup_printf (_("%s of %s"), current_str, total_str);

  g_free (total_str);
  g_free (current_str);
  g_free (speed_str);

  if (percentage != NULL)
    {
      if (total != 0)
        *percentage = current * 100 / total;
      else
        *percentage = -1;
    }

  return retval;
}
Exemple #2
0
static void
update_information_widget ()
{
	gchar *path = g_downloadable_get_save_path (selected_download);
	gchar *size_str = g_format_size_for_display (g_downloadable_get_size (selected_download));
	gchar *downloaded_str = g_format_size_for_display (g_downloadable_get_downloaded_size (selected_download));

	gchar time_str[128];
	time_t time = g_downloadable_get_start_time (selected_download);
	struct tm *started_time = localtime (&time);
	strftime (time_str, 128, "%a %d %b %R %p", started_time);

	gtk_label_set_text (GTK_LABEL (size), size_str);
	gtk_label_set_text (GTK_LABEL (location), path);
	gtk_label_set_text (GTK_LABEL (downloaded), downloaded_str);
	gtk_label_set_text (GTK_LABEL (started), time_str);
	gtk_label_set_text (GTK_LABEL (url), g_downloadable_get_url (selected_download));

	Category *cat = g_downloadable_get_category (selected_download);

	if (cat == NULL)
		gtk_label_set_text (GTK_LABEL (category), _("Unknown"));
	else
		gtk_label_set_text (GTK_LABEL (category), category_get_name (cat));

	g_free (path);
	g_free (size_str);
	g_free (downloaded_str);
}
void gtkhash_hash_file_report_cb(void *data, goffset file_size,
	goffset total_read, GTimer *timer)
{
	gdk_threads_enter();

	struct page_s *page = data;

	gtk_progress_bar_set_fraction(page->progressbar,
		(double)total_read /
		(double)file_size);

	double elapsed = g_timer_elapsed(timer, NULL);
	if (elapsed <= 1)
		goto out;

	// Update progressbar text...
	unsigned int s = elapsed / total_read * (file_size - total_read);
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 30))
	char *total_read_str = g_format_size_for_display(total_read);
	char *file_size_str = g_format_size_for_display(file_size);
	char *speed_str = g_format_size_for_display(total_read / elapsed);
#else
	char *total_read_str = g_format_size(total_read);
	char *file_size_str = g_format_size(file_size);
	char *speed_str = g_format_size(total_read / elapsed);
#endif
	char *text;
	if (s > 60) {
		unsigned int m = s / 60;
		if (m == 1)
			text = g_strdup_printf(_("%s of %s - 1 minute left (%s/sec)"),
				total_read_str, file_size_str, speed_str);
		else
			text = g_strdup_printf(_("%s of %s - %u minutes left (%s/sec)"),
				total_read_str, file_size_str, m, speed_str);
	} else {
		if (s == 1)
			text = g_strdup_printf(_("%s of %s - 1 second left (%s/sec)"),
				total_read_str, file_size_str, speed_str);
		else
			text = g_strdup_printf(_("%s of %s - %u seconds left (%s/sec)"),
				total_read_str, file_size_str, s, speed_str);
	}
	gtk_progress_bar_set_text(page->progressbar, text);
	g_free(text);
	g_free(speed_str);
	g_free(file_size_str);
	g_free(total_read_str);

out:
	gdk_threads_leave();
}
static void
gth_metadata_provider_file_read (GthMetadataProvider *self,
				 GthFileData         *file_data,
				 const char          *attributes)
{
	GFileAttributeMatcher *matcher;
	char                  *value;
	GTimeVal              *timeval_p;
	const char            *value_s;

	matcher = g_file_attribute_matcher_new (attributes);

	value = g_format_size_for_display (g_file_info_get_size (file_data->info));
	g_file_info_set_attribute_string (file_data->info, "gth::file::display-size", value);
	g_free (value);

	timeval_p = gth_file_data_get_modification_time (file_data);
	value = _g_time_val_strftime (timeval_p, "%x %X");
	g_file_info_set_attribute_string (file_data->info, "gth::file::display-mtime", value);
	g_free (value);

	value = g_file_get_parse_name (file_data->file);
	g_file_info_set_attribute_string (file_data->info, "gth::file::full-name", value);
	g_free (value);

	value_s = get_static_string (g_file_info_get_content_type (file_data->info));
	if (value_s != NULL)
		g_file_info_set_attribute_string (file_data->info, "gth::file::content-type", value_s);

	g_file_attribute_matcher_unref (matcher);
}
Exemple #5
0
JNIEXPORT jstring JNICALL
Java_org_gnome_glib_GlibMisc_g_1format_1size_1for_1display
(
	JNIEnv* env,
	jclass cls,
	jlong _size
)
{
	char* result;
	jstring _result;
	goffset size;

	// convert parameter size
	size = (goffset) _size;

	// call function
	result = g_format_size_for_display(size);

	// cleanup parameter size

	// translate return value to JNI type
	_result = (jstring) bindings_java_newString(env, result);

	// cleanup return value
	if (result != NULL) {
		g_free(result);
	}

	// and finally
	return _result;
}
char *
mpd_storage_device_tile_get_title (MpdStorageDeviceTile *self)
{
  MpdStorageDeviceTilePrivate *priv = GET_PRIVATE (self);
  int64_t  size = -1;
  int64_t  available_size = -1;
  char    *markup = NULL;

  if (priv->storage)
  {
    g_object_get (priv->storage,
                  "size", &size,
                  "available-size", &available_size,
                  NULL);

  }

  if (size > -1 && available_size > -1)
  {
    unsigned int percentage = 100 - (double) available_size / size * 100;
    char *size_text = g_format_size_for_display (size);
    markup = g_strdup_printf (_("<span font-weight='bold'>%s</span> using "
                                "<span color='%s'>%d%% of %s</span>"),
                              priv->name,
                              TEXT_COLOR,
                              percentage,
                              size_text);
    g_free (size_text);
  } else {
    markup = g_strdup_printf (_("<span font-weight='bold'>%s</span>"),
                              priv->name);
  }

  return markup;
}
static void
update_album_list (DialogData *data)
{
	GtkTreeIter  iter;
	GList       *scan;
	char        *free_space;

	g_return_if_fail (data->user != NULL);

	free_space = g_format_size_for_display (data->user->quota_limit - data->user->quota_current);
	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("free_space_label")), free_space);
	g_free (free_space);

	gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("album_liststore")));
	for (scan = data->albums; scan; scan = scan->next) {
		PicasaWebAlbum *album = scan->data;
		char           *n_photos_remaining;
		char           *used_bytes;

		n_photos_remaining = g_strdup_printf ("%d", album->n_photos_remaining);
		used_bytes = g_format_size_for_display (album->used_bytes);

		gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("album_liststore")), &iter);
		gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("album_liststore")), &iter,
				    ALBUM_DATA_COLUMN, album,
				    ALBUM_ICON_COLUMN, "file-catalog",
				    ALBUM_NAME_COLUMN, album->title,
				    ALBUM_REMAINING_IMAGES_COLUMN, n_photos_remaining,
				    ALBUM_USED_BYTES_COLUMN, used_bytes,
				    -1);

		if (album->access == PICASA_WEB_ACCESS_PRIVATE)
			gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("album_liststore")), &iter,
					    ALBUM_EMBLEM_COLUMN, "emblem-readonly",
					    -1);

		g_free (used_bytes);
		g_free (n_photos_remaining);
	}

	gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE);
}
Exemple #8
0
static void
show_progress (goffset current_num_bytes,
	       goffset total_num_bytes,
	       gpointer user_data)
{
  GTimeVal tv;
  char *size;

  g_get_current_time (&tv);

  size = g_format_size_for_display (current_num_bytes / MAX (tv.tv_sec - start_time.tv_sec, 1));
  g_print ("progress %"G_GINT64_FORMAT"/%"G_GINT64_FORMAT" (%s/s)\n",
	   current_num_bytes, total_num_bytes, size);
  g_free (size);
}
static void
image_scale_confirm_large (ImageScaleDialog *dialog,
                           gint64            new_memsize,
                           gint64            max_memsize)
{
  GtkWidget *widget = image_scale_confirm_dialog (dialog);
  gchar     *size;

  size = g_format_size_for_display (new_memsize);
  gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (widget)->box,
                                     _("You are trying to create an image "
                                       "with a size of %s."), size);
  g_free (size);

  size = g_format_size_for_display (max_memsize);
  gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (widget)->box,
                             _("Scaling the image to the chosen size will "
                               "make it use more memory than what is "
                               "configured as \"Maximum Image Size\" in the "
                               "Preferences dialog (currently %s)."), size);
  g_free (size);

  gtk_widget_show (widget);
}
Exemple #10
0
char*
tr_strlsize( char *  buf,
             guint64 size,
             size_t  buflen )
{
    if( !size )
        g_strlcpy( buf, _( "None" ), buflen );
#if GLIB_CHECK_VERSION( 2, 16, 0 )
    else
    {
        char * tmp = g_format_size_for_display( size );
        g_strlcpy( buf, tmp, buflen );
        g_free( tmp );
    }
#else
    else if( size < (guint64)KILOBYTE_FACTOR )
static void
mail_attachment_bar_update_status (EMailAttachmentBar *bar)
{
	EAttachmentView *view;
	EAttachmentStore *store;
	GtkActivatable *activatable;
	GtkAction *action;
	GtkLabel *label;
	gint num_attachments;
	guint64 total_size;
	gchar *display_size;
	gchar *markup;

	view = E_ATTACHMENT_VIEW (bar);
	store = e_attachment_view_get_store (view);
	label = GTK_LABEL (bar->priv->status_label);

	num_attachments = e_attachment_store_get_num_attachments (store);
	total_size = e_attachment_store_get_total_size (store);
	display_size = g_format_size_for_display (total_size);

	if (total_size > 0)
		markup = g_strdup_printf (
			"<b>%d</b> %s (%s)", num_attachments, ngettext (
			"Attachment", "Attachments", num_attachments),
			display_size);
	else
		markup = g_strdup_printf (
			"<b>%d</b> %s", num_attachments, ngettext (
			"Attachment", "Attachments", num_attachments));
	gtk_label_set_markup (label, markup);
	g_free (markup);

	activatable = GTK_ACTIVATABLE (bar->priv->save_all_button);
	action = gtk_activatable_get_related_action (activatable);
	gtk_action_set_visible (action, (num_attachments > 1));

	activatable = GTK_ACTIVATABLE (bar->priv->save_one_button);
	action = gtk_activatable_get_related_action (activatable);
	gtk_action_set_visible (action, (num_attachments == 1));

	g_free (display_size);
}
Exemple #12
0
const char*
mu_str_size_s  (size_t s)
{
	static char buf[32];

#ifdef HAVE_GLIB216
	char *tmp;

	tmp = g_format_size_for_display ((goffset)s);
	strncpy (buf, tmp, sizeof(buf));
	buf[sizeof(buf) -1] = '\0'; /* just in case */
	g_free (tmp);

#else
	if (s >= 1000 * 1000)
		g_snprintf(buf, sizeof(buf), "%.1f MB",
			   (double)s/(1000*1000));
	else
		g_snprintf(buf, sizeof(buf), "%.1f kB", (double)s/(1000));
#endif /*HAVE_GLIB216*/


	return buf;
}
static void
update (MpdDiskTile *self)
{
  MpdDiskTilePrivate *priv = GET_PRIVATE (self);
  char          *markup;
  char          *size_text;
  uint64_t       size;
  uint64_t       available_size;
  unsigned int   percentage;

  g_object_get (priv->storage,
                "size", &size,
                "available-size", &available_size,
                NULL);

  percentage = 100 - (double) available_size / size * 100;


  /* We don't want to display 0% used, we still have *something* installed */
  if (percentage == 0)
    percentage++;

  size_text = g_format_size_for_display (size);
  markup = g_strdup_printf (_("You are using %d%% of %s"),
                            percentage,
                            size_text);
  clutter_text_set_markup (CLUTTER_TEXT (mx_label_get_clutter_text (
                            MX_LABEL (priv->label))), markup);
  g_free (markup);
  g_free (size_text);

  /* The progress bar does not look good if the percentage < 3%. We cheat
   * and always display a minimum of 3% */
  mx_progress_bar_set_progress (MX_PROGRESS_BAR (priv->meter),
                                MAX (.03, percentage / 100.));
}
Exemple #14
0
/* Something very similar to g_format_size_for_display() but for rates.
 * This should give the same display as in g-s-m */
static char*
format_rate_for_display(guint rate)
{
	char* bytes = g_format_size_for_display(rate);
	return g_strdup_printf(_("%s/s"), bytes);
}
static gboolean
copy_uri (const gchar  *src_uri,
          const gchar  *dest_uri,
          const gchar  *copying_format_str,
          const gchar  *copied_format_str,
          GError      **error)
{
  GnomeVFSHandle   *read_handle;
  GnomeVFSHandle   *write_handle;
  GnomeVFSFileInfo *src_info;
  GnomeVFSFileSize  file_size  = 0;
  GnomeVFSFileSize  bytes_read = 0;
  guchar            buffer[BUFSIZE];
  GnomeVFSResult    result;
  gchar            *memsize;
  GTimeVal          last_time = { 0, 0 };

  gimp_progress_init (_("Connecting to server"));

  src_info = gnome_vfs_file_info_new ();
  result = gnome_vfs_get_file_info (src_uri, src_info, 0);

  /*  ignore errors here, they will be noticed below  */
  if (result == GNOME_VFS_OK &&
      (src_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE))
    {
      file_size = src_info->size;
    }

  gnome_vfs_file_info_unref (src_info);

  result = gnome_vfs_open (&read_handle, src_uri, GNOME_VFS_OPEN_READ);

  if (result != GNOME_VFS_OK)
    {
      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                   _("Could not open '%s' for reading: %s"),
                   src_uri, gnome_vfs_result_to_string (result));
      return FALSE;
    }

  result = gnome_vfs_create (&write_handle, dest_uri,
                             GNOME_VFS_OPEN_WRITE, FALSE, 0644);

  if (result != GNOME_VFS_OK)
    {
      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                   _("Could not open '%s' for writing: %s"),
                   dest_uri, gnome_vfs_result_to_string (result));
      gnome_vfs_close (read_handle);
      return FALSE;
    }

  memsize = g_format_size_for_display (file_size);

  gimp_progress_init_printf (file_size > 0 ?
                             copying_format_str : copied_format_str,
                             memsize);

  g_free (memsize);

  while (TRUE)
    {
      GnomeVFSFileSize  chunk_read;
      GnomeVFSFileSize  chunk_written;
      GTimeVal          now;

      result = gnome_vfs_read (read_handle, buffer, sizeof (buffer),
                               &chunk_read);

      if (chunk_read == 0)
        {
          if (result != GNOME_VFS_ERROR_EOF)
            {
              memsize = g_format_size_for_display (sizeof (buffer));
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                           _("Failed to read %s from '%s': %s"),
                           memsize, src_uri,
                           gnome_vfs_result_to_string (result));
              g_free (memsize);

              gnome_vfs_close (read_handle);
              gnome_vfs_close (write_handle);
              return FALSE;
            }
          else
            {
              gimp_progress_update (1.0);
              break;
            }
        }

      bytes_read += chunk_read;

      /*  update the progress only up to 10 times a second  */

      g_get_current_time (&now);

      if (((now.tv_sec - last_time.tv_sec) * 1000 +
           (now.tv_usec - last_time.tv_usec) / 1000) > 100)
        {
          if (file_size > 0)
            {
              gimp_progress_update ((gdouble) bytes_read / (gdouble) file_size);
            }
          else
            {
              memsize = g_format_size_for_display (bytes_read);

              gimp_progress_set_text_printf (copied_format_str, memsize);
              gimp_progress_pulse ();

              g_free (memsize);
            }

          last_time = now;
        }

      result = gnome_vfs_write (write_handle, buffer, chunk_read,
                                &chunk_written);

      if (chunk_written < chunk_read)
        {
          memsize = g_format_size_for_display (chunk_read);
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("Failed to write %s to '%s': %s"),
                       memsize, dest_uri,
                       gnome_vfs_result_to_string (result));
          g_free (memsize);

          gnome_vfs_close (read_handle);
          gnome_vfs_close (write_handle);
          return FALSE;
        }
    }

  gnome_vfs_close (read_handle);
  gnome_vfs_close (write_handle);

  return TRUE;
}
static void
pd_update_general_tab (EomPropertiesDialog *prop_dlg,
                       EomImage            *image)
{
    gchar *bytes_str, *dir_str, *uri_str;
    gchar *width_str, *height_str;
    GFile *file;
    GFileInfo *file_info;
    const char *mime_str;
    char *type_str;
    gint width, height;
    goffset bytes;

    g_object_set (G_OBJECT (prop_dlg->priv->thumbnail_image),
                  "pixbuf", eom_image_get_thumbnail (image),
                  NULL);

    gtk_label_set_text (GTK_LABEL (prop_dlg->priv->name_label),
                        eom_image_get_caption (image));

    eom_image_get_size (image, &width, &height);

    width_str = g_strdup_printf ("%d %s", width,
                                 ngettext ("pixel", "pixels", width));
    height_str = g_strdup_printf ("%d %s", height,
                                  ngettext ("pixel", "pixels", height));

    gtk_label_set_text (GTK_LABEL (prop_dlg->priv->width_label), width_str);

    gtk_label_set_text (GTK_LABEL (prop_dlg->priv->height_label),
                        height_str);

    g_free (height_str);
    g_free (width_str);

    file = eom_image_get_file (image);
    file_info = g_file_query_info (file,
                                   G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
                                   0, NULL, NULL);
    if (file_info == NULL) {
        type_str = g_strdup (_("Unknown"));
    } else {
        mime_str = g_file_info_get_content_type (file_info);
        type_str = g_content_type_get_description (mime_str);
        g_object_unref (file_info);
    }

    gtk_label_set_text (GTK_LABEL (prop_dlg->priv->type_label), type_str);

    bytes = eom_image_get_bytes (image);
    bytes_str = g_format_size_for_display (bytes);

    gtk_label_set_text (GTK_LABEL (prop_dlg->priv->bytes_label), bytes_str);

    uri_str = eom_image_get_uri_for_display (image);
    dir_str = g_path_get_dirname (uri_str);
    gtk_label_set_text (GTK_LABEL (prop_dlg->priv->location_label),
                        dir_str);

    g_free (type_str);
    g_free (bytes_str);
    g_free (dir_str);
    g_free (uri_str);
}
void
dlg_export_to_picasaweb (GthBrowser *browser,
		         GList      *file_list)
{
	DialogData       *data;
	GtkTreeSelection *selection;
	GList            *scan;
	int               n_total;
	goffset           total_size;
	char             *total_size_formatted;
	char             *text;

	data = g_new0 (DialogData, 1);
	data->browser = browser;
	data->location = gth_file_data_dup (gth_browser_get_location_data (browser));
	data->builder = _gtk_builder_new_from_file ("export-to-picasaweb.ui", "picasaweb");
	data->dialog = _gtk_builder_get_widget (data->builder, "export_dialog");
	data->cancellable = g_cancellable_new ();

	{
		GtkCellLayout   *cell_layout;
		GtkCellRenderer *renderer;

		cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("name_treeviewcolumn"));

		renderer = gtk_cell_renderer_pixbuf_new ();
		gtk_cell_layout_pack_start (cell_layout, renderer, FALSE);
		gtk_cell_layout_set_attributes (cell_layout, renderer,
						"icon-name", ALBUM_ICON_COLUMN,
						NULL);

		renderer = gtk_cell_renderer_text_new ();
		gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
		gtk_cell_layout_set_attributes (cell_layout, renderer,
						"text", ALBUM_NAME_COLUMN,
						NULL);

		renderer = gtk_cell_renderer_pixbuf_new ();
		gtk_cell_layout_pack_start (cell_layout, renderer, FALSE);
		gtk_cell_layout_set_attributes (cell_layout, renderer,
						"icon-name", ALBUM_EMBLEM_COLUMN,
						NULL);
	}

	_gtk_window_resize_to_fit_screen_height (data->dialog, 500);

	data->file_list = NULL;
	n_total = 0;
	total_size = 0;
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;
		const char  *mime_type;

		mime_type = gth_file_data_get_mime_type (file_data);
		if (g_content_type_equals (mime_type, "image/bmp")
		    || g_content_type_equals (mime_type, "image/gif")
		    || g_content_type_equals (mime_type, "image/jpeg")
		    || g_content_type_equals (mime_type, "image/png"))
		{
			total_size += g_file_info_get_size (file_data->info);
			n_total++;
			data->file_list = g_list_prepend (data->file_list, g_object_ref (file_data));
		}
	}
	data->file_list = g_list_reverse (data->file_list);

	if (data->file_list == NULL) {
		GError *error;

		if (data->conn != NULL)
			gth_task_dialog (GTH_TASK (data->conn), TRUE);

		error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected."));
		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not export the files"), &error);
		destroy_dialog (data);
		return;
	}

	total_size_formatted = g_format_size_for_display (total_size);
	text = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, total_size_formatted);
	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text);
	g_free (text);
	g_free (total_size_formatted);

	/* Set the widget data */

	data->list_view = gth_file_list_new (GTH_FILE_LIST_TYPE_NO_SELECTION, FALSE);
	gth_file_list_set_thumb_size (GTH_FILE_LIST (data->list_view), 112);
	gth_file_view_set_spacing (GTH_FILE_VIEW (gth_file_list_get_view (GTH_FILE_LIST (data->list_view))), 0);
	gth_file_list_enable_thumbs (GTH_FILE_LIST (data->list_view), TRUE);
	gth_file_list_set_caption (GTH_FILE_LIST (data->list_view), "none");
	gth_file_list_set_sort_func (GTH_FILE_LIST (data->list_view), gth_main_get_sort_type ("file::name")->cmp_func, FALSE);
	gtk_widget_show (data->list_view);
	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->list_view, TRUE, TRUE, 0);
	gth_file_list_set_files (GTH_FILE_LIST (data->list_view), data->file_list);

	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("album_liststore")), ALBUM_NAME_COLUMN, GTK_SORT_ASCENDING);

	gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE);

	/* Set the signals handlers. */

	g_signal_connect (data->dialog,
			  "delete-event",
			  G_CALLBACK (gtk_widget_hide_on_delete),
			  NULL);
	g_signal_connect (data->dialog,
			  "response",
			  G_CALLBACK (export_dialog_response_cb),
			  data);
	g_signal_connect (GET_WIDGET ("add_album_button"),
			  "clicked",
			  G_CALLBACK (add_album_button_clicked_cb),
			  data);
	g_signal_connect (GET_WIDGET ("edit_accounts_button"),
			  "clicked",
			  G_CALLBACK (edit_accounts_button_clicked_cb),
			  data);
	g_signal_connect (GET_WIDGET ("account_combobox"),
			  "changed",
			  G_CALLBACK (account_combobox_changed_cb),
			  data);

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("albums_treeview")));
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
	g_signal_connect (selection,
			  "changed",
			  G_CALLBACK (albums_treeview_selection_changed_cb),
			  data);

	data->accounts = picasa_web_accounts_load_from_file (&data->email);
	auto_select_account (data);
}
Exemple #18
0
gboolean
uri_backend_load_image (const gchar  *uri,
                        const gchar  *tmpname,
                        GimpRunMode   run_mode,
                        GError      **error)
{
  gint pid;
  gint p[2];

  if (pipe (p) != 0)
    {
      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                   "pipe() failed: %s", g_strerror (errno));
      return FALSE;
    }

  /*  open a process group, so killing the plug-in will kill wget too  */
  setpgid (0, 0);

  if ((pid = fork()) < 0)
    {
      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                   "fork() failed: %s", g_strerror (errno));
      return FALSE;
    }
  else if (pid == 0)
    {
      gchar timeout_str[16];

      close (p[0]);
      close (2);
      dup (p[1]);
      close (p[1]);

      /* produce deterministic output */
      g_setenv ("LANGUAGE", "C", TRUE);
      g_setenv ("LC_ALL", "C", TRUE);
      g_setenv ("LANG", "C", TRUE);

      g_snprintf (timeout_str, sizeof (timeout_str), "%d", TIMEOUT);

      execlp ("wget",
              "wget", "-v", "-e", "server-response=off", "--progress=dot", "-T", timeout_str,
              uri, "-O", tmpname, NULL);
      _exit (127);
    }
  else
    {
      FILE     *input;
      gchar     buf[BUFSIZE];
      gboolean  seen_resolve = FALSE;
      gboolean  seen_ftp     = FALSE;
      gboolean  connected    = FALSE;
      gboolean  redirect     = FALSE;
      gboolean  file_found   = FALSE;
      gchar     sizestr[37];
      gchar    *endptr;
      guint64   size         = 0;
      gint      i, j;
      gchar     dot;
      guint64   kilobytes    = 0;
      gboolean  finished     = FALSE;
      gboolean  debug        = FALSE;
      gchar    *memsize;
      gchar    *message;
      gchar    *timeout_msg;

#define DEBUG(x) if (debug) g_printerr (x)

      close (p[1]);

      input = fdopen (p[0], "r");

      /*  hardcoded and not-really-foolproof scanning of wget putput  */

    wget_begin:
      /* Eat any Location lines */
      if (redirect && fgets (buf, sizeof (buf), input) == NULL)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("wget exited abnormally on URI '%s'"), uri);
          return FALSE;
        }

      redirect = FALSE;

      if (fgets (buf, sizeof (buf), input) == NULL)
        {
          /*  no message here because failing on the first line means
           *  that wget was not found
           */
          return FALSE;
        }

      DEBUG (buf);

      /*  The second line is the local copy of the file  */
      if (fgets (buf, sizeof (buf), input) == NULL)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("wget exited abnormally on URI '%s'"), uri);
          return FALSE;
        }
      /* with an ftp url wget has a "=> `filename.foo" */
      else if ( !seen_ftp && strstr (buf, "=> `"))
        {
          seen_ftp = TRUE;
        }

      DEBUG (buf);

      /*  The third line is "Connecting to..."  */

      timeout_msg = g_strdup_printf (ngettext ("(timeout is %d second)",
                                               "(timeout is %d seconds)",
                                               TIMEOUT), TIMEOUT);

      gimp_progress_init_printf ("%s %s",
                                 _("Connecting to server"), timeout_msg);

    read_connect:
      if (fgets (buf, sizeof (buf), input) == NULL)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("wget exited abnormally on URI '%s'"), uri);
          return FALSE;
        }
      else if (strstr (buf, "connected"))
        {
          connected = TRUE;
        }
      /* newer wgets have a "Resolving foo" line, so eat it */
      else if (!seen_resolve && strstr (buf, "Resolving"))
        {
          seen_resolve = TRUE;
          goto read_connect;
        }

      DEBUG (buf);

      /*  The fourth line is either the network request or an error  */

      gimp_progress_set_text_printf ("%s %s", _("Opening URI"), timeout_msg);

      if (fgets (buf, sizeof (buf), input) == NULL)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("wget exited abnormally on URI '%s'"), uri);
          return FALSE;
        }
      else if (! connected)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("A network error occurred: %s"), buf);

          DEBUG (buf);

          return FALSE;
        }
      /* on successful ftp login wget prints a "Logged in" message */
      else if ( seen_ftp && !strstr(buf, "Logged in!"))
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("A network error occurred: %s"), buf);

          DEBUG (buf);

          return FALSE;
        }
      else if (strstr (buf, "302 Found"))
        {
          DEBUG (buf);

          connected = FALSE;
          seen_resolve = FALSE;

          redirect = TRUE;
          goto wget_begin;
        }

      DEBUG (buf);

      /* for an ftp session wget has extra output*/
    ftp_session:
      if (seen_ftp)
        {
          if (fgets (buf, sizeof (buf), input) == NULL)
            {
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                           _("A network error occurred: %s"), buf);

              DEBUG (buf);

              return FALSE;
            }
          /* if there is no size output file does not exist on server */
          else if (strstr (buf, "==> SIZE") && strstr (buf, "... done"))
            {
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                           _("wget exited abnormally on URI '%s'"), uri);

              DEBUG (buf);

              return FALSE;
            }
          /* while no PASV line we eat other messages */
          else if (!strstr (buf, "==> PASV"))
            {
              DEBUG (buf);
              goto ftp_session;
            }
        }

      /*  The fifth line is either the length of the file or an error  */
      if (fgets (buf, sizeof (buf), input) == NULL)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("wget exited abnormally on URI '%s'"), uri);
          return FALSE;
        }
      else if (strstr (buf, "Length"))
        {
          file_found = TRUE;
        }
      else
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       _("A network error occurred: %s"), buf);

          DEBUG (buf);

          return FALSE;
        }

      DEBUG (buf);

      if (sscanf (buf, "Length: %37s", sizestr) != 1)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       "Could not parse wget's file length message");
          return FALSE;
        }

      /*  strip away commas  */
      for (i = 0, j = 0; i < sizeof (sizestr); i++, j++)
        {
          if (sizestr[i] == ',')
            i++;

          sizestr[j] = sizestr[i];

          if (sizestr[j] == '\0')
            break;
        }

      if (*sizestr != '\0')
        {
          size = g_ascii_strtoull (sizestr, &endptr, 10);

          if (*endptr != '\0' || size == G_MAXUINT64)
            size = 0;
        }

      /* on http sessions wget has "Saving to: ..." */
      if (!seen_ftp)
        {
          if (fgets (buf, sizeof (buf), input) == NULL)
            {
              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                           _("wget exited abnormally on URI '%s'"), uri);

              return FALSE;
            }
        }

      /*  Start the actual download...  */
      if (size > 0)
        {
          memsize = g_format_size_for_display (size);
          message = g_strdup_printf (_("Downloading %s of image data"),
                                     memsize);
        }
      else
        {
          message = g_strdup (_("Downloading unknown amount of image data"));
          memsize = NULL;
        }

      gimp_progress_set_text_printf ("%s %s", message, timeout_msg);

      g_free (message);
      g_free (memsize);

      /*  Switch to byte parsing wget's output...  */

      while (TRUE)
        {
          dot = fgetc (input);

          if (feof (input))
            break;

          if (debug)
            {
              fputc (dot, stderr);
              fflush (stderr);
            }

          if (dot == '.')  /* one kilobyte */
            {
              kilobytes++;

              if (size > 0)
                {
                  gimp_progress_update ((gdouble) (kilobytes * 1024) /
                                        (gdouble) size);
                }
              else
                {
                  memsize = g_format_size_for_display (kilobytes * 1024);

                  gimp_progress_set_text_printf
                    (_("Downloaded %s of image data"), memsize);
                  gimp_progress_pulse ();

                  g_free (memsize);
                }
            }
          else if (dot == ':')  /* the time string contains a ':' */
            {
              fgets (buf, sizeof (buf), input);

              DEBUG (buf);

              if (! strstr (buf, "error"))
                {
                  finished = TRUE;
                  gimp_progress_update (1.0);
                }

              break;
            }
        }

      if (! finished)
        {
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                       "wget exited before finishing downloading URI\n'%s'",
                       uri);
          return FALSE;
        }
    }

  return TRUE;
}
Exemple #19
0
void
checkcopy_worker (CheckcopyWorkerParams * params)
{
  GQueue *int_q;

  ProgressDialog * progress_dialog;
  CheckcopyPlanner *planner;
  CheckcopyProcessor *proc;
  CheckcopyFileList * list;

  gboolean verify_only;

  verify_only = g_file_has_uri_scheme (params->dest, "verify");

  list = checkcopy_file_list_get_instance ();
  g_object_set (G_OBJECT (list), "verify-only", verify_only, NULL);

  progress_dialog = params->progress_dialog;
  planner = checkcopy_planner_new (progress_dialog);
  proc = checkcopy_processor_new (progress_dialog, params->dest, verify_only);

  int_q = g_queue_new ();

  ext_q = params->queue;

  g_async_queue_ref (ext_q);

  while (TRUE) {
    GFile *file;

    /* Collect everything from the external queue to calculate the size.
     * Since the files are not processed yet, stick them into the internal queue.
     *
     * At this point the internal queue is empty, so we can block once for getting the first item
     * from the external queue
    */
    file = g_async_queue_pop (ext_q);

    progress_dialog_thread_set_status (progress_dialog, PROGRESS_DIALOG_STATUS_CALCULATING_SIZE);

    do {
      g_queue_push_tail (int_q, file);
      checkcopy_traverse (file, CHECKCOPY_FILE_HANDLER (planner));
    } while ((file = g_async_queue_try_pop (ext_q)) != NULL);

#ifdef DEBUG
    {
    gchar *size_str;
    guint64 total_size = 0;

    g_object_get (planner, "total-size", &total_size, NULL);
    size_str = g_format_size_for_display (total_size);

    DBG ("Total size is now %s", size_str);
    g_free (size_str);
    }
#endif

    progress_dialog_thread_set_status (progress_dialog, PROGRESS_DIALOG_STATUS_COPYING);
    g_object_set (G_OBJECT (progress_dialog), "num-files", checkcopy_planner_get_num_files (planner), NULL);

    /* Now process the internal queue */
    while ((file = g_queue_pop_head (int_q)) != NULL) {
      checkcopy_traverse (file, CHECKCOPY_FILE_HANDLER (proc));
      g_object_unref (file);
    }

    checkcopy_file_list_write_checksum (list, params->dest);
    checkcopy_file_list_sweep (list);

    progress_dialog_thread_set_status (progress_dialog, PROGRESS_DIALOG_STATUS_COMPLETED);

#ifdef DEBUG
    progress_dialog_thread_check_stats (progress_dialog);
#endif

    DBG ("Waiting for more things to do");
  }

  /* we won't ever get here but just in case
   * we change the loop condition later */

  g_async_queue_unref (ext_q);
  g_queue_foreach (int_q, (GFunc) g_object_unref, NULL);
  g_queue_free (int_q);

  g_object_unref (planner);
  g_object_unref (proc);
  g_object_unref (list);

  g_object_unref (params->dest);
  g_free (params);
}
Exemple #20
0
/*!
 * \brief Check and - if huge - let the user confirm the diagram size before export
 */
gboolean
confirm_export_size (Diagram *dia, GtkWindow *parent, guint flags)
{
  GtkWidget *dialog;
  int pages = 0;
  gint64 bytes = 0;
  gchar *size, *msg;
  gboolean ret;
 
  pages = ceil((dia->data->extents.right - dia->data->extents.left) / dia->data->paper.width)
        * ceil((dia->data->extents.bottom - dia->data->extents.top) /  dia->data->paper.height);
  /* three guesses: 4 bytes per pixel, 20 pixels per cm; using * dia->data->paper.scaling  */
  bytes = (gint64)4
        * ceil((dia->data->extents.right - dia->data->extents.left) * dia->data->paper.scaling * 20)
        * ceil((dia->data->extents.bottom - dia->data->extents.top) * dia->data->paper.scaling * 20);

  if ((flags & CONFIRM_PRINT) && (pages < 10)) /* hardcoded limits for the dialog to show */
    return TRUE;
  else if ((flags & CONFIRM_MEMORY) && (bytes < (G_GINT64_CONSTANT(100)<<16)))
    return TRUE; /* smaller than 100MB  */
  else if ((flags & CONFIRM_PAGES) && (pages < 50))
    return TRUE;
  
  /* message and limits depend on the flags give */
#if GLIB_CHECK_VERSION(2,30,0)
  size = g_format_size (bytes);
#else
  size = g_format_size_for_display (bytes);
#endif
  /* See: https://live.gnome.org/TranslationProject/DevGuidelines/Plurals */
  if (flags & CONFIRM_PRINT)
    msg = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
		"You are about to print a diagram with %d page.", /* not triggered */
		"You are about to print a diagram with %d pages.", pages), pages);
  else if ((flags & ~CONFIRM_PAGES) == 0)
    msg = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
		"You are about to export a diagram with %d page.",  /* not triggered */
		"You are about to export a diagram with %d pages.", pages), pages);
  else
    msg = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
		"You are about to export a diagram which may require %s of memory.(%d page).",
		"You are about to export a diagram which may require %s of memory.(%d pages).", pages),
		size, pages);
  dialog = gtk_message_dialog_new (parent, /* diagrams display 'shell' */
				   GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
				   GTK_MESSAGE_WARNING,
				   GTK_BUTTONS_OK_CANCEL,
				   "%s", msg);
  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), 
					    _("You can adjust the size of the diagram by changing "
					      "the 'Scaling' in the 'Page Setup' dialog.\n"
					      "Alternatively use 'Best Fit' "
					      "to move objects/handles into the intended bounds."));
  gtk_window_set_title (GTK_WINDOW (dialog), _("Confirm Diagram Size"));
  g_free (size);

  g_signal_connect(G_OBJECT (dialog), "response",
		   G_CALLBACK(confirm_respond), NULL);

  ret = (GTK_RESPONSE_OK == gtk_dialog_run (GTK_DIALOG (dialog)));
  gtk_widget_destroy(dialog);
  return ret;
}
static void
rejilla_status_dialog_update (RejillaStatusDialog *self,
			      RejillaStatus *status)
{
	gchar *string;
	gchar *size_str;
	goffset session_bytes;
	gchar *current_action;
	RejillaBurnResult res;
	RejillaTrackType *type;
	RejillaStatusDialogPrivate *priv;

	priv = REJILLA_STATUS_DIALOG_PRIVATE (self);

	current_action = rejilla_status_get_current_action (status);
	if (current_action) {
		gchar *string;

		string = g_strdup_printf ("<i>%s</i>", current_action);
		gtk_label_set_markup (GTK_LABEL (priv->action), string);
		g_free (string);
	}
	else
		gtk_label_set_markup (GTK_LABEL (priv->action), "");

	g_free (current_action);

	if (rejilla_status_get_progress (status) < 0.0)
		gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->progress));
	else
		gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress),
					       rejilla_status_get_progress (status));

	res = rejilla_burn_session_get_size (priv->session,
					     NULL,
					     &session_bytes);
	if (res != REJILLA_BURN_OK)
		return;

	type = rejilla_track_type_new ();
	rejilla_burn_session_get_input_type (priv->session, type);

	if (rejilla_track_type_get_has_stream (type)) {
		if (REJILLA_STREAM_FORMAT_HAS_VIDEO (rejilla_track_type_get_stream_format (type))) {
			guint64 free_time;

			/* This is an embarassing problem: this is an approximation based on the fact that
			 * 2 hours = 4.3GiB */
			free_time = session_bytes * 72000LL / 47LL;
			size_str = rejilla_units_get_time_string (free_time,
			                                          TRUE,
			                                          TRUE);
		}
		else
			size_str = rejilla_units_get_time_string (session_bytes, TRUE, FALSE);
	}
	/* NOTE: this is perfectly fine as rejilla_track_type_get_medium_type ()
	 * will return REJILLA_MEDIUM_NONE if this is not a MEDIUM track type */
	else if (rejilla_track_type_get_medium_type (type) & REJILLA_MEDIUM_HAS_AUDIO)
		size_str = rejilla_units_get_time_string (session_bytes, TRUE, FALSE);
	else
		size_str = g_format_size_for_display (session_bytes);

	rejilla_track_type_free (type);

	string = g_strdup_printf (_("Estimated size: %s"), size_str);
	g_free (size_str);

	gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress), string);
	g_free (string);
}
static VALUE
rbglib_m_format_size_for_display(G_GNUC_UNUSED VALUE self, VALUE size)
{
    return CSTR2RVAL_FREE(g_format_size_for_display(NUM2ULONG(size)));
}