static GtkWidget *
cc_sharing_panel_new_media_sharing_row (const char     *uri_or_path,
                                        CcSharingPanel *self)
{
  GtkWidget *row, *box, *w;
  GUserDirectory dir = G_USER_N_DIRECTORIES;
  GIcon *icon;
  guint i;
  char *basename, *path;
  GFile *file;

  file = g_file_new_for_commandline_arg (uri_or_path);
  path = g_file_get_path (file);
  g_object_unref (file);

  row = gtk_list_box_row_new ();
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  gtk_container_set_border_width (GTK_CONTAINER (box), 12);
  gtk_container_add (GTK_CONTAINER (row), box);

  /* Find the icon and create it */
  for (i = 0; i < G_USER_N_DIRECTORIES; i++)
    {
      if (g_strcmp0 (path, g_get_user_special_dir (i)) == 0)
        {
          dir = i;
          break;
        }
    }

  icon = special_directory_get_gicon (dir);
  w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
  gtk_widget_set_margin_end (w, 12);
  gtk_container_add (GTK_CONTAINER (box), w);
  g_object_unref (icon);

  /* Label */
  basename = g_filename_display_basename (path);
  w = gtk_label_new (basename);
  g_free (basename);
  gtk_container_add (GTK_CONTAINER (box), w);

  /* Remove button */
  w = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
  gtk_button_set_relief (GTK_BUTTON (w), GTK_RELIEF_NONE);
  gtk_widget_set_margin_top (w, 3);
  gtk_widget_set_margin_bottom (w, 3);
  gtk_widget_set_margin_end (w, 12);
  gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
  gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (w), "clicked",
                    G_CALLBACK (cc_sharing_panel_remove_folder), self);
  g_object_set_data (G_OBJECT (w), "row", row);

  g_object_set_data_full (G_OBJECT (row), "path", g_strdup (path), g_free);

  gtk_widget_show_all (row);

  return row;
}
Esempio n. 2
0
/* Load a skin (TilEm v2.00 only) */
int skin_load(SKIN_INFOS *si, const char *filename, GError **err)
{
	FILE *fp;
	int ret = 0, errnum;
	char *dname;

	g_return_val_if_fail(err == NULL || *err == NULL, -1);

	fp = g_fopen(filename, "rb");
	if (fp == NULL) {
		errnum = errno;
		dname = g_filename_display_basename(filename);
		g_set_error(err, G_FILE_ERROR, g_file_error_from_errno(errnum),
		            _("Unable to open %s for reading: %s"),
		            dname, g_strerror(errnum));
		g_free(dname);
		return -1;
	}

	ret = skin_read_header(si, fp);
	if (ret) {
		fclose(fp);
		dname = g_filename_display_basename(filename);
		g_set_error(err, SKIN_ERROR, SKIN_ERROR_INVALID,
		            _("The file %s is not a valid skin."), dname);
		g_free(dname);
		return -1;
	}

	ret = skin_read_image(si, fp, err);

	fclose(fp);

	return ret;
}
Esempio n. 3
0
static void
psppire_window_set_property (GObject         *object,
			     guint            prop_id,
			     const GValue    *value,
			     GParamSpec      *pspec)
{
  PsppireWindow *window = PSPPIRE_WINDOW (object);

  switch (prop_id)
    {
    case PROP_DESCRIPTION:
      g_free (window->description);
      window->description = g_value_dup_string (value);
      psppire_window_set_title (window);
      break;
    case PROP_FILENAME:
      g_free (window->filename);
      window->filename = g_value_dup_string (value);
      g_free (window->basename);
      window->basename = (window->filename
                          ? g_filename_display_basename (window->filename)
                          : NULL);
      psppire_window_name_changed (window);
      break;
      break;
    case PROP_ID:
      g_free (window->id);
      window->id = g_value_dup_string (value);
      psppire_window_name_changed (window);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    };
}
Esempio n. 4
0
gchar *
file_utils_uri_display_basename (const gchar *uri)
{
    gchar *basename = NULL;

    g_return_val_if_fail (uri != NULL, NULL);

    if (g_str_has_prefix (uri, "file:"))
    {
        gchar *filename = file_utils_filename_from_uri (uri);

        if (filename)
        {
            basename = g_filename_display_basename (filename);
            g_free (filename);
        }
    }
    else
    {
        gchar *name = file_utils_uri_display_name (uri);

        basename = strrchr (name, '/');
        if (basename)
            basename = g_strdup (basename + 1);

        g_free (name);
    }

    return basename ? basename : file_utils_uri_to_utf8_basename (uri);
}
Esempio n. 5
0
/*
 * Alert box for a failed attempt to close a capture file.
 * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value.
 *
 * When closing a capture file:
 *
 *    some information in the file that can't be determined until
 *    all packets have been written might be written to the file
 *    (such as a table of the file offsets of all packets);
 *
 *    data buffered in the low-level file writing code might be
 *    flushed to the file;
 *
 *    for remote file systems, data written to the file but not
 *    yet sent to the server might be sent to the server or, if
 *    that data was sent asynchronously, "out of space", "disk
 *    quota exceeded", or "I/O error" indications might have
 *    been received but not yet delivered, and the close operation
 *    could deliver them;
 *
 * so we have to check for write errors here.
 *
 * XXX - add explanatory secondary text for at least some of the errors;
 * various HIGs suggest that you should, for example, suggest that the
 * user remove files if the file system is full.  Perhaps that's because
 * they're providing guidelines for people less sophisticated than the
 * typical Wireshark user is, but....
 */
void
cfile_close_failure_alert_box(const char *filename, int err)
{
    gchar *display_basename;

    if (err < 0) {
        /* Wiretap error. */
        display_basename = g_filename_display_basename(filename);
        switch (err) {

        case WTAP_ERR_CANT_CLOSE:
            simple_error_message_box(
                        "The file \"%s\" couldn't be closed for some unknown reason.",
                        display_basename);
            break;

        case WTAP_ERR_SHORT_WRITE:
            simple_error_message_box(
                        "A full write couldn't be done to the file \"%s\".",
                        display_basename);
            break;

        default:
            simple_error_message_box(
                        "An error occurred while closing the file \"%s\": %s.",
                        display_basename, wtap_strerror(err));
            break;
        }
        g_free(display_basename);
    } else {
        /* OS error.
           We assume that a close error from the OS is really a write error. */
        write_failure_alert_box(filename, err);
    }
}
static void
palette_import_file_callback (GtkWidget    *widget,
                              ImportDialog *dialog)
{
  gchar *filename;

  if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
    return;

  dialog->import_type = FILE_IMPORT;

  filename =
    gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog->file_chooser));

  if (filename)
    {
      gchar *basename = g_filename_display_basename (filename);

      /* TODO: strip filename extension */
      gtk_entry_set_text (GTK_ENTRY (dialog->entry), basename);
      g_free (basename);

      g_free (filename);
    }
  else
    {
      gtk_entry_set_text (GTK_ENTRY (dialog->entry), "");
    }

  palette_import_set_sensitive (dialog);
}
Esempio n. 7
0
GimpPlugIn *
gimp_plug_in_new (GimpPlugInManager   *manager,
                  GimpContext         *context,
                  GimpProgress        *progress,
                  GimpPlugInProcedure *procedure,
                  const gchar         *prog)
{
  GimpPlugIn *plug_in;

  g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL);
  g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (procedure == NULL ||
                        GIMP_IS_PLUG_IN_PROCEDURE (procedure), NULL);
  g_return_val_if_fail (prog == NULL || g_path_is_absolute (prog), NULL);
  g_return_val_if_fail ((procedure != NULL || prog != NULL) &&
                        ! (procedure != NULL && prog != NULL), NULL);

  plug_in = g_object_new (GIMP_TYPE_PLUG_IN, NULL);

  if (! prog)
    prog = gimp_plug_in_procedure_get_progname (procedure);

  gimp_object_take_name (GIMP_OBJECT (plug_in),
                         g_filename_display_basename (prog));

  plug_in->manager = manager;
  plug_in->prog    = g_strdup (prog);

  gimp_plug_in_proc_frame_init (&plug_in->main_proc_frame,
                                context, progress, procedure);

  return plug_in;
}
Esempio n. 8
0
static void
add_recent_file (const gchar *filename)
{
	GtkRecentData recent_data;
	gchar *uri = NULL;

#ifdef G_OS_WIN32
	recent_data.mime_type = get_mime_type_from_uri (filename, NULL);
#else
	recent_data.mime_type = get_mime_type (filename);
#endif

	if (recent_data.mime_type == NULL)
		return;

	recent_data.display_name = g_filename_display_basename (filename);
	recent_data.app_name = g_strdup (g_get_application_name ());
	recent_data.app_exec =  g_strjoin (" ", g_get_prgname (), "%u", NULL);
	recent_data.description = NULL;
	recent_data.groups = NULL;
	recent_data.is_private = FALSE;

	uri = g_filename_to_uri(filename, NULL, NULL);
	gtk_recent_manager_add_full(gtk_recent_manager_get_default(), uri, &recent_data);

	g_free (recent_data.display_name);
	g_free (recent_data.mime_type);
	g_free (recent_data.app_name);
	g_free (recent_data.app_exec);
	g_free (uri);
}
Esempio n. 9
0
/*
 * Alert box for a failed attempt to write to a file.
 * "err" is assumed to be a UNIX-style errno if positive and a
 * Wiretap error if negative.
 *
 * XXX - add explanatory secondary text for at least some of the errors;
 * various HIGs suggest that you should, for example, suggest that the
 * user remove files if the file system is full.  Perhaps that's because
 * they're providing guidelines for people less sophisticated than the
 * typical Wireshark user is, but....
 */
void
write_failure_alert_box(const char *filename, int err)
{
    gchar *display_basename;

    display_basename = g_filename_display_basename(filename);
    if (err < 0) {
        switch (err) {

        case WTAP_ERR_SHORT_WRITE:
            simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
                              "A full write couldn't be done to the file \"%s\".",
                              display_basename);
        break;

        default:
            simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
                              "An error occurred while writing to the file \"%s\": %s.",
                              display_basename, wtap_strerror(err));
        break;
        }
    } else {
        simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
                           file_write_error_message(err), display_basename);
    }
    g_free(display_basename);
}
Esempio n. 10
0
PrintDialog::PrintDialog(QWidget *parent, capture_file *cf) :
    QDialog(parent),
    pd_ui_(new Ui::PrintDialog),
    cur_printer_(NULL),
    cur_painter_(NULL),
    preview_(new QPrintPreviewWidget(&printer_)),
    print_bt_(new QPushButton(tr("&Print..."))),
    cap_file_(cf)
{
    if (!cf) done(QDialog::Rejected); // ...or assert?

    pd_ui_->setupUi(this);

    pd_ui_->previewLayout->insertWidget(0, preview_, Qt::AlignTop);

    preview_->setMinimumWidth(preview_->height() / 2);
    preview_->setToolTip(pd_ui_->zoomLabel->toolTip());

    // XXX Make these configurable
    header_font_.setFamily("Times");
    header_font_.setPointSizeF(header_font_.pointSizeF() * 0.8);
    packet_font_ = wsApp->monospaceFont();
    packet_font_.setPointSizeF(packet_font_.pointSizeF() * 0.8);

    memset(&print_args_, 0, sizeof(print_args_));
    memset(&stream_ops_, 0, sizeof(stream_ops_));

    /* Init the export range */
    packet_range_init(&print_args_.range, cap_file_);
    /* Default to displayed packets */
    print_args_.range.process_filtered = TRUE;

    stream_ops_.print_preamble = print_preamble_pd;
    stream_ops_.print_line     = print_line_pd;
    stream_ops_.new_page       = new_page_pd;

    stream_.data = this;
    stream_.ops = &stream_ops_;
    print_args_.stream = &stream_;

    gchar *display_basename = g_filename_display_basename(cap_file_->filename);
    printer_.setDocName(display_basename);
    g_free(display_basename);

    pd_ui_->rangeGroupBox->initRange(&print_args_.range);

    pd_ui_->buttonBox->addButton(print_bt_, QDialogButtonBox::ActionRole);
    pd_ui_->buttonBox->addButton(tr("Page &Setup..."), QDialogButtonBox::ResetRole);
    print_bt_->setDefault(true);

    connect(preview_, SIGNAL(paintRequested(QPrinter*)), this, SLOT(paintPreview(QPrinter*)));
    connect(pd_ui_->rangeGroupBox, SIGNAL(rangeChanged()),
            this, SLOT(checkValidity()));
    connect(pd_ui_->formatGroupBox, SIGNAL(formatChanged()),
            this, SLOT(checkValidity()));
    connect(pd_ui_->formFeedCheckBox, SIGNAL(toggled(bool)),
            preview_, SLOT(updatePreview()));

    checkValidity();
}
Esempio n. 11
0
static void _cvs_refresh(CVS * cvs, GList * selection)
{
	char * path = (selection != NULL) ? selection->data : NULL;
	struct stat st;
	gchar * p;

	if(cvs->source != 0)
		g_source_remove(cvs->source);
	free(cvs->filename);
	cvs->filename = NULL;
	if(lstat(path, &st) != 0)
		return;
	if((cvs->filename = strdup(path)) == NULL)
		return;
	p = g_filename_display_basename(path);
	gtk_label_set_text(GTK_LABEL(cvs->name), p);
	g_free(p);
	_refresh_status(cvs, NULL);
	gtk_widget_hide(cvs->directory);
	gtk_widget_hide(cvs->file);
	gtk_widget_hide(cvs->add);
	gtk_widget_hide(cvs->make);
	if(S_ISDIR(st.st_mode))
		_refresh_dir(cvs);
	else
		_refresh_file(cvs);
	_refresh_make(cvs, &st);
}
Esempio n. 12
0
static gchar *
get_object_name (const gchar *dir,
                 gchar       *filename,
                 void        *context)
{
  gchar *ret = NULL, *unprocessed_line = NULL;
  gchar *full_path = NULL;

  /* First try to extract the object's name (= user-friendly description)
   * from the preset file
   * */

  full_path = g_build_filename (dir, filename, NULL);

  unprocessed_line = get_early_line_from_preset (full_path, "name=");
  if (unprocessed_line)
    {
      ret = g_strcompress (unprocessed_line);
      g_free (unprocessed_line);
    }
  else
    {
      /* The object name defaults to a filename-derived description */
      ret = g_filename_display_basename (full_path);
    }

  g_free (full_path);

  return ret;
}
static void
palette_import_filename_changed (GtkFileChooser *button,
                                 ImportDialog   *dialog)
{
  gchar *filename;

  if (dialog->import_type != FILE_IMPORT)
    return;

  filename = gtk_file_chooser_get_filename (button);

  if (filename)
    {
      gchar *basename = g_filename_display_basename (filename);

      /* TODO: strip filename extension */
      gtk_entry_set_text (GTK_ENTRY (dialog->entry), basename);
      g_free (basename);
    }
  else
    {
      gtk_entry_set_text (GTK_ENTRY (dialog->entry), "");
    }

  g_free (filename);

  palette_import_make_palette (dialog);
}
Esempio n. 14
0
static void on_add( GtkButton* btn, gpointer data )
{
    GtkWindow* parent = GTK_WINDOW(data);
    GtkTreeViewColumn* col;
    GtkTreeIter it, new_it, *pit;
    GtkTreePath* tree_path;
    GtkTreeView* view = (GtkTreeView*)g_object_get_data( G_OBJECT(data),
                                                         "list_view" );
    GtkTreeModel* model;
    GtkTreeSelection* sel = gtk_tree_view_get_selection( view );

    GdkPixbuf* icon = gtk_icon_theme_load_icon( gtk_icon_theme_get_default(),
                                                "gnome-fs-directory",
                                                20, 0, NULL );
    GtkWidget* dlg;
    char *path = NULL, *basename = NULL;

    if( gtk_tree_selection_get_selected ( sel, &model, &it ) )
    {
        tree_path = gtk_tree_model_get_path( model, &it );
        gtk_tree_path_next( tree_path );
        pit = &it;
    }
    else
    {
        tree_path = gtk_tree_path_new_first();
        pit = NULL;
    }

    dlg = gtk_file_chooser_dialog_new( NULL, parent,
                            GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OK, GTK_RESPONSE_OK, NULL );
    if( gtk_dialog_run( (GtkDialog*) dlg ) == GTK_RESPONSE_OK )
    {
        path = gtk_file_chooser_get_filename( (GtkFileChooser*)dlg );
        basename = g_filename_display_basename( path );
    }
    gtk_widget_destroy( dlg );

    col = gtk_tree_view_get_column( view, 1 );
    gtk_list_store_insert_after( GTK_LIST_STORE(model), &new_it, pit );
    gtk_list_store_set( GTK_LIST_STORE(model), &new_it,
                        COL_ICON, icon,
                        COL_NAME, basename ? basename : _("New Item"),
                        COL_DIRPATH, path, -1);

    g_free( path );
    g_free( basename );

    if( tree_path )
    {
        gtk_tree_view_set_cursor_on_cell( view, tree_path, col, NULL, TRUE );
        gtk_tree_path_free( tree_path );
    }

    if( icon )
        g_object_unref( icon );
}
Esempio n. 15
0
/**
 * gnm_app_history_get_list:
 *
 * creating it if necessary.
 *
 * Return value: (element-type char) (transfer full): the list, which must be
 * freed along with the strings in it.
 **/
GSList *
gnm_app_history_get_list (int max_elements)
{
	GSList *res = NULL;
	GList *items, *l;
	GtkFileFilter *filter;
	int n_elements = 0;

	if (app->recent == NULL)
		return NULL;

	items = gtk_recent_manager_get_items (app->recent);
	items = g_list_sort (items, (GCompareFunc)compare_mru);

	filter = gnm_app_create_opener_filter (NULL);

	for (l = items; l && n_elements < max_elements; l = l->next) {
		GtkRecentInfo *ri = l->data;
		const char *uri = gtk_recent_info_get_uri (ri);
		gboolean want_it;

		if (gtk_recent_info_has_application (ri, g_get_application_name ())) {
			want_it = TRUE;
		} else {
			GtkFileFilterInfo fi;
			char *display_name = g_filename_display_basename (uri);

			memset (&fi, 0, sizeof (fi));
			fi.contains = (GTK_FILE_FILTER_MIME_TYPE |
				       GTK_FILE_FILTER_URI |
				       GTK_FILE_FILTER_DISPLAY_NAME);
			fi.uri = uri;
			fi.mime_type = gtk_recent_info_get_mime_type (ri);
			fi.display_name = display_name;
			want_it = gtk_file_filter_filter (filter, &fi);
			g_free (display_name);
		}

		if (want_it) {
			char *filename = go_filename_from_uri (uri);
			if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
				want_it = FALSE;
			g_free (filename);
		}

		if (want_it) {
			res = g_slist_prepend (res, g_strdup (uri));
			n_elements++;
		}
	}

	g_list_free_full (items, (GDestroyNotify)gtk_recent_info_unref);
	g_object_ref_sink (filter);
	g_object_unref (filter);

	return g_slist_reverse (res);
}
Esempio n. 16
0
/*
 * diagram_get_name:
 *
 * Get the name of the currently opened diagram.
 */
static gchar *
diagram_get_name (LdWindowMain *self)
{
	g_return_val_if_fail (LD_IS_WINDOW_MAIN (self), NULL);

	if (self->priv->filename)
		return g_filename_display_basename (self->priv->filename);
	else
		return g_strdup (_("Unsaved Diagram"));
}
Esempio n. 17
0
static void update_completion( GtkEntry* entry,
                               GtkEntryCompletion* completion )
{
    char* new_dir, *fn;
    const char* old_dir;
    GtkListStore* list;
    const char *sep;

    sep = strrchr( gtk_entry_get_text(entry), '/' );
    if( sep )
        fn = (char*)sep + 1;
    else
        fn = (char*)gtk_entry_get_text(entry);

    g_object_set_data_full( G_OBJECT(completion), "fn", g_strdup(fn), (GDestroyNotify)g_free );

    new_dir = path_entry_active_path();
    old_dir = (const char*)g_object_get_data( (GObject*)completion, "cwd" );
    if( old_dir && new_dir && 0 == g_ascii_strcasecmp( old_dir, new_dir ) )
    {
        g_free( new_dir );
        return;
    }
    g_object_set_data_full( (GObject*)completion, "cwd",
                            new_dir, g_free );
    list = (GtkListStore*)gtk_entry_completion_get_model( completion );
    gtk_list_store_clear( list );
    if( new_dir )
    {
        GDir* dir;
        if( (dir = g_dir_open( new_dir, 0, NULL )) )
        {
            const char* name;
            while( (name = g_dir_read_name( dir )) )
            {
                char* full_path = g_build_filename( new_dir, name, NULL );
//	printf("%d fn=%s\n",xxx++, full_path);
                if( g_file_test( full_path, G_FILE_TEST_IS_DIR ) )
                {
                    GtkTreeIter it;
                    char* disp_name = g_filename_display_basename( full_path );
                    gtk_list_store_append( list, &it );
                    gtk_list_store_set( list, &it, COL_NAME, disp_name, COL_PATH, full_path, -1 );
                    g_free( disp_name );
                }
                g_free( full_path );
            }
            g_dir_close( dir );

            gtk_entry_completion_set_match_func( completion, match_func, new_dir, NULL );
        }
        else
            gtk_entry_completion_set_match_func( completion, NULL, NULL, NULL );
    }
}
Esempio n. 18
0
static void process_found_files( FindFile* data, GQueue* queue, const char* path )
{
    char *name;
    gsize len, term;
    GtkTreeIter it;
    VFSFileInfo* fi;
    GdkPixbuf* icon;
    FoundFile* ff;

    if( path )
    {
        name = g_filename_display_basename( path );
        fi = vfs_file_info_new();
        if( vfs_file_info_get( fi, path, name ) )
        {
            ff = g_slice_new0( FoundFile );
            ff->fi = fi;
            ff->dir_path = g_path_get_dirname( path );
            g_queue_push_tail( queue, ff );
        }
        else
        {
            vfs_file_info_unref( fi );
        }
        g_free( name );

        /* we queue the found files, and not add them to the tree view direclty.
         * when we queued more than 10 files, we add them at once. I think
         * this can prevent locking gtk+ too frequently and improve responsiveness.
         * FIXME: This could blocked the last queued files and delay their display
         * to the end of the whole search. A better method is needed.
         */
//MOD disabled this - causes last queued files to not display
//        if( g_queue_get_length( queue ) < 10 )
//            return;
    }

    while( ff = (FoundFile*)g_queue_pop_head(queue) )
    {
        GDK_THREADS_ENTER();
        gtk_list_store_append( data->result_list, &it );
        icon = vfs_file_info_get_small_icon( ff->fi );
        gtk_list_store_set( data->result_list, &it,
                                    COL_ICON, icon,
                                    COL_NAME, vfs_file_info_get_disp_name(ff->fi),
                                    COL_DIR, ff->dir_path, /* FIXME: non-UTF8? */
                                    COL_TYPE, vfs_file_info_get_mime_type_desc( ff->fi ),
                                    COL_SIZE, vfs_file_info_get_disp_size( ff->fi ),
                                    COL_MTIME, vfs_file_info_get_disp_mtime( ff->fi ),
                                    COL_INFO, ff->fi, -1 );
        g_object_unref( icon );
        GDK_THREADS_LEAVE();
        g_slice_free( FoundFile, ff );
    }
}
Esempio n. 19
0
static void
url_renderer_func (GtkTreeViewColumn *tree_column,
		   GtkCellRenderer   *cell,
		   GtkTreeModel      *model,
		   GtkTreeIter       *iter,
		   gpointer           user_data)
{
	GtkRecentInfo *ri = NULL;
	const char *uri;
	char *markup, *shortname, *filename, *longname;

	gtk_tree_model_get (model, iter, RECENT_COL_INFO, &ri, -1);

	uri = gtk_recent_info_get_uri (ri);
	filename = go_filename_from_uri (uri);
	if (filename) {
		shortname = g_filename_display_basename (filename);
	} else {
		shortname = g_filename_display_basename (uri);
	}

	if (filename) {
		longname = g_strdup (filename);
	} else {
		char *duri = g_uri_unescape_string (uri, NULL);
		longname = duri
			? g_filename_display_name (duri)
			: g_strdup (uri);
		g_free (duri);
	}

	markup = g_markup_printf_escaped (_("<b>%s</b>\n"
					    "<small>Location: %s</small>"),
					  shortname,
					  longname);
	g_object_set (cell, "markup", markup, NULL);
	g_free (markup);
	g_free (shortname);
	g_free (longname);
	g_free (filename);
	gtk_recent_info_unref (ri);
}
Esempio n. 20
0
/*
 * Alert box for a failed attempt to open or create a file.
 * "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if
 * the file is being opened for writing and FALSE if it's being opened
 * for reading.
 *
 * XXX - add explanatory secondary text for at least some of the errors;
 * various HIGs suggest that you should, for example, suggest that the
 * user remove files if the file system is full.  Perhaps that's because
 * they're providing guidelines for people less sophisticated than the
 * typical Wireshark user is, but....
 */
void
open_failure_alert_box(const char *filename, int err, gboolean for_writing)
{
    gchar *display_basename;

    display_basename = g_filename_display_basename(filename);
    simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
                        file_open_error_message(err, for_writing),
                        display_basename);
    g_free(display_basename);
}
Esempio n. 21
0
/*
 * Alert box for a failed attempt to read a file.
 * "err" is assumed to be a UNIX-style errno.
 */
void
read_failure_alert_box(const char *filename, int err)
{
    gchar *display_basename;

    display_basename = g_filename_display_basename(filename);
    simple_message_box(ESD_TYPE_ERROR, NULL, NULL,
                       "An error occurred while reading from the file \"%s\": %s.",
                       display_basename, g_strerror(err));
    g_free(display_basename);
}
Esempio n. 22
0
static gboolean
callback_outputfile (const gchar *option_name, const gchar *value,
                     gpointer user_data, GError **error)
{
    AppData *app_data = (AppData *) user_data;

    g_free(app_data->filename);
    app_data->filename = g_filename_display_basename (value);
    g_free(app_data->outputfile);
    app_data->outputfile = g_strdup (value);
    return TRUE;
}
Esempio n. 23
0
static void _check_native_display_names(FmPath *path)
{
    char *path_str, *disp_name;

    if (path == NULL || _fm_path_get_display_name(path) != NULL)
        return; /* all done */
    path_str = fm_path_to_str(path);
    disp_name = g_filename_display_basename(path_str);
    g_free(path_str);
    _fm_path_set_display_name(path, disp_name);
    g_free(disp_name);
    _check_native_display_names(fm_path_get_parent(path)); /* recursion */
}
Esempio n. 24
0
static int _refresh_name(Preview * preview, char const * path)
{
	BrowserPluginHelper * helper = preview->helper;
	gchar * p;

	free(preview->path);
	if((preview->path = strdup(path)) == NULL)
		return -helper->error(helper->browser, strerror(errno), 1);
	p = g_filename_display_basename(path);
	gtk_label_set_text(GTK_LABEL(preview->name), p);
	g_free(p);
	return 0;
}
Esempio n. 25
0
/* Runs the wipe operation */
static void
nw_extension_run_delete_operation (GtkWindow *parent,
                                   GList     *files)
{
  gchar  *confirm_primary_text = NULL;
  guint   n_items;
  
  n_items = g_list_length (files);
  if (n_items > 1) {
    confirm_primary_text = g_strdup_printf (g_dngettext(GETTEXT_PACKAGE,
    /* TRANSLATORS: singular is not really used, N is strictly >1 */
                                                        "Are you sure you want "
                                                        "to wipe the %u "
                                                        "selected items?",
                                                        /* plural form */
                                                        "Are you sure you want "
                                                        "to wipe the %u "
                                                        "selected items?",
                                                        n_items),
                                            n_items);
  } else if (n_items > 0) {
    gchar *name;
    
    name = g_filename_display_basename (files->data);
    confirm_primary_text = g_strdup_printf (_("Are you sure you want to wipe "
                                              "\"%s\"?"),
                                            name);
    g_free (name);
  }
  nw_operation_manager_run (
    parent, files,
    /* confirm dialog */
    confirm_primary_text,
    _("If you wipe an item, it will not be recoverable."),
    _("_Wipe"),
    gtk_image_new_from_stock (GTK_STOCK_DELETE, GTK_ICON_SIZE_BUTTON),
    /* progress dialog */
    _("Wiping files..."),
    /* operation launcher */
    nw_delete_operation_new (),
    /* failed dialog */
    _("Wipe failed."),
    /* success dialog */
    _("Wipe successful."),
    _("Item(s) have been successfully wiped.")
  );
  g_free (confirm_primary_text);
}
/* query any plug-ins that changed since we last wrote out pluginrc */
static void
gimp_plug_in_manager_query_new (GimpPlugInManager  *manager,
                                GimpContext        *context,
                                GimpInitStatusFunc  status_callback)
{
  GSList *list;
  gint    n_plugins;

  status_callback (_("Querying new Plug-ins"), "", 0.0);

  for (list = manager->plug_in_defs, n_plugins = 0; list; list = list->next)
    {
      GimpPlugInDef *plug_in_def = list->data;

      if (plug_in_def->needs_query)
        n_plugins++;
    }

  if (n_plugins)
    {
      gint nth;

      manager->write_pluginrc = TRUE;

      for (list = manager->plug_in_defs, nth = 0; list; list = list->next)
        {
          GimpPlugInDef *plug_in_def = list->data;

          if (plug_in_def->needs_query)
            {
              gchar *basename;

              basename = g_filename_display_basename (plug_in_def->prog);
              status_callback (NULL, basename,
                               (gdouble) nth++ / (gdouble) n_plugins);
              g_free (basename);

              if (manager->gimp->be_verbose)
                g_print ("Querying plug-in: '%s'\n",
                         gimp_filename_to_utf8 (plug_in_def->prog));

              gimp_plug_in_manager_call_query (manager, context, plug_in_def);
            }
        }
    }

  status_callback (NULL, "", 1.0);
}
Esempio n. 27
0
gchar* get_display_filename(const gchar *filename, gboolean get_folder)
{
	gchar *utf8_filename = NULL;
	gchar *dir = NULL;

	/* Get the containing folder of the file or the file itself ? */
	if (get_folder) {
		dir = g_path_get_dirname(filename);
		utf8_filename = g_filename_display_name(dir);
		g_free(dir);
	}
	else {
		utf8_filename = g_filename_display_basename(filename);
	}
	return utf8_filename;
}
Esempio n. 28
0
/* {{{ proto string Glib::displayBasename(string filename)
	   Returns the display basename for the particular filename, guaranteed to be valid UTF-8.
      */
PHP_METHOD(Glib, displayBasename)
{
	char *filename, *display_name;
	int length;
	GError *error = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &length) == FAILURE) {
		return;
	}

	display_name = g_filename_display_basename((const gchar*)filename);
	if (php_glib_handle_gerror(&error TSRMLS_CC)) {
		return;
	}
	RETURN_STRING(display_name, 1);
}
int CMasterBiasDlg::ProcessFiles(CProgressDlg *sender)
{
	int frameid, res;
	char *fpath, *fbase, msg[128];
	GtkTreePath *path;
	CMasterBiasProc mbias;

	m_InFiles = 0;
	sender->Print("------ Make master bias frame ------");

	res = mbias.Open(sender, m_FilePath);
	if (res==0) {
		for (GList *node = m_FileList; node != NULL; node = node->next) {
			path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
			if (path) {
				frameid = g_Project->GetFrameID(path);
				fpath = g_Project->GetImageFileName(path);
				sender->SetFileName(fpath);
				g_free(fpath);
				sender->SetProgress(m_InFiles++);
				sprintf(msg, "Frame #%d:", frameid);
				sender->Print(msg);
				res = mbias.Add(path);
				gtk_tree_path_free(path);
			}
			if (res!=0 || sender->Cancelled()) 
				break;
		}
		if (res==0 && !sender->Cancelled()) {
			sender->SetTitle("Making output file");
			fbase = g_filename_display_basename(m_FilePath);
			sender->SetFileName(fbase);
			g_free(fbase);
			res = mbias.Close();
		}
		if (sender->Cancelled())
			sprintf(msg, "Cancelled at the user's request");
		else
			sprintf(msg, "====== %d succeeded ======", m_InFiles);
		sender->Print(msg);
	} else {
		char *aux = cmpack_formaterror(res);
		sender->Print(aux);
		cmpack_free(aux);
	}
	return res;
}
Esempio n. 30
0
int
main (int argc, char *argv[])
{
  MechArea *scroll, *text;
  MechWindow *window;
  MechTextBuffer *buffer;
  GMainLoop *main_loop;
  gint n_paragraphs = 0;

  if (argc > 1)
    n_paragraphs = atoi (argv[1]);

  if (n_paragraphs <= 0)
    {
      gchar *basename;

      basename = g_filename_display_basename (argv[0]);
      g_print ("Usage: %s <n-paragraphs>\n\n", basename);
      n_paragraphs = 10000;
      g_free (basename);
    }

  main_loop = g_main_loop_new (NULL, FALSE);

  window = mech_window_new ();
  mech_window_set_title (window, "Text");
  g_signal_connect (window, "close-request",
                    G_CALLBACK (window_close_request), main_loop);

  scroll = mech_scroll_area_new (MECH_AXIS_FLAG_Y);
  mech_area_set_preferred_size (scroll, MECH_AXIS_X, MECH_UNIT_PX, 500);
  mech_area_set_preferred_size (scroll, MECH_AXIS_Y, MECH_UNIT_PX, 500);
  mech_area_add (mech_container_get_root (MECH_CONTAINER (window)), scroll);

  text = mech_text_input_new ();
  mech_area_add (scroll, text);

  buffer = create_buffer (n_paragraphs);
  mech_text_set_buffer (MECH_TEXT (text), buffer);

  mech_window_set_visible (window, TRUE);
  g_main_loop_run (main_loop);

  return 0;
}