Exemple #1
0
static gint mimeview_key_pressed(GtkWidget *widget, GdkEventKey *event,
				 MimeView *mimeview)
{
	SummaryView *summaryview = NULL;
	GtkTreeView *treeview = GTK_TREE_VIEW(widget);
	GtkTreeModel *model = GTK_TREE_MODEL(mimeview->store);
	GtkTreeIter iter;
	gboolean mod_pressed;

	if (!event) return FALSE;
	if (!mimeview->opened) return FALSE;
	if (!gtk_tree_model_get_iter(model, &iter, mimeview->opened))
		return FALSE;

	if (mimeview->messageview->mainwin)
		summaryview = mimeview->messageview->mainwin->summaryview;
	mod_pressed =
		((event->state & (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);

	switch (event->keyval) {
	case GDK_space:
	case GDK_KP_Space:
		if (textview_scroll_page(mimeview->textview, mod_pressed))
			return TRUE;

		if (gtkut_tree_model_next(model, &iter)) {
			GtkTreePath *path;

			path = gtk_tree_model_get_path(model, &iter);
			gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
			gtk_tree_path_free(path);
			return TRUE;
		}
		if (summaryview)
			summary_pass_key_press_event(summaryview, event);
		break;
	case GDK_BackSpace:
		textview_scroll_page(mimeview->textview, TRUE);
		return TRUE;
	case GDK_Return:
	case GDK_KP_Enter:
		textview_scroll_one_line(mimeview->textview, mod_pressed);
		return TRUE;
	case GDK_t:
		BREAK_ON_MODIFIER_KEY();
		KEY_PRESS_EVENT_STOP();
		mimeview_display_as_text(mimeview);
		return TRUE;
	case GDK_Escape:
		if (summaryview)
			gtk_widget_grab_focus(summaryview->treeview);
		break;
	case GDK_Left:
	case GDK_Delete:
	case GDK_KP_Left:
	case GDK_KP_Delete:
		if (summaryview)
			summary_pass_key_press_event(summaryview, event);
		break;
	default:
		break;
	}

	return FALSE;
}
Exemple #2
0
static gint
on_view_event_after (GtkWidget *tree_view,
		     GdkEventButton *event,
		     gpointer data)
{
  RosterViewGtk *self = NULL;
  GtkTreeModel *model = NULL;
  GtkTreePath *path = NULL;
  GtkTreeIter iter;

  // take into account only clicks and Enter keys
  if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS && event->type != GDK_KEY_PRESS)
    return FALSE;
  if (event->type == GDK_KEY_PRESS && ((GdkEventKey*)event)->keyval != GDK_KEY_Return && ((GdkEventKey*)event)->keyval != GDK_KEY_KP_Enter)
    return FALSE;

  self = ROSTER_VIEW_GTK (data);
  model = gtk_tree_view_get_model (self->priv->tree_view);

  // get the line clicked or currently selected
  gboolean ret = true;
  if (event->type == GDK_KEY_PRESS)
    gtk_tree_view_get_cursor (GTK_TREE_VIEW (tree_view), &path, NULL);
  else
    ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view),
                                         (gint) event->x, (gint) event->y,
                                         &path, NULL, NULL, NULL);

  if (!ret)
    return TRUE;  // click on an empty line

  if (gtk_tree_model_get_iter (model, &iter, path)) {

    gint column_type;
    gchar *name = NULL;
    gchar *group_name = NULL;
    Ekiga::Heap *heap = NULL;
    Ekiga::Presentity *presentity = NULL;
    gtk_tree_model_get (model, &iter,
                        COLUMN_NAME, &name,
                        COLUMN_GROUP_NAME, &group_name,
                        COLUMN_TYPE, &column_type,
                        COLUMN_HEAP, &heap,
                        COLUMN_PRESENTITY, &presentity,
                        -1);

    switch (column_type) {

    case TYPE_HEAP:

      if (event->type == GDK_BUTTON_PRESS && event->button == 1 && name)
        on_clicked_fold (self, path, name);
      if (event->type == GDK_BUTTON_PRESS && event->button == 3)
        on_clicked_show_heap_menu (heap, event);
      break;
    case TYPE_GROUP:

      if (event->type == GDK_BUTTON_PRESS && event->button == 1 && group_name)
        on_clicked_fold (self, path, group_name);
      if (event->type == GDK_BUTTON_PRESS && event->button == 3)
        on_clicked_show_heap_group_menu (heap, group_name, event);
      break;
    case TYPE_PRESENTITY:

      if (event->type == GDK_BUTTON_PRESS && event->button == 3)
        on_clicked_show_presentity_menu (heap, presentity, event);
      if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_KEY_PRESS)
        on_clicked_trigger_presentity (presentity);
      break;
    default:

      g_assert_not_reached ();
      break; // shouldn't happen
    }
    g_free (name);
  }
  gtk_tree_path_free (path);

  return TRUE;
}
Exemple #3
0
static void
clipboard_received_cb (GtkClipboard     *clipboard,
		       GtkSelectionData *selection_data,
		       gpointer          user_data)
{
	PasteData   *paste_data = user_data;
	GthBrowser  *browser = paste_data->browser;
	const char  *raw_data;
	char       **clipboard_data;
	int          i;
	GtkTreePath *path;
	int          position;
	GthTask     *task;

	raw_data = (const char *) gtk_selection_data_get_data (selection_data);
	if (raw_data == NULL) {
		paste_data_free (paste_data);
		return;
	}

	clipboard_data = g_strsplit_set (raw_data, "\n\r", -1);
	if ((clipboard_data == NULL) || (clipboard_data[0] == NULL)) {
		g_strfreev (clipboard_data);
		paste_data_free (paste_data);
		return;
	}

	paste_data->cut = strcmp (clipboard_data[0], "cut") == 0;
	paste_data->files = NULL;
	for (i = 1; clipboard_data[i] != NULL; i++)
		if (strcmp (clipboard_data[i], "") != 0)
			paste_data->files = g_list_prepend (paste_data->files, g_file_new_for_uri (clipboard_data[i]));
	paste_data->files = g_list_reverse (paste_data->files);
	paste_data->file_source = gth_main_get_file_source (paste_data->destination->file);

	if (paste_data->cut && ! gth_file_source_can_cut (paste_data->file_source, paste_data->files->data)) {
		GtkWidget *dialog;
		int        response;

		dialog = _gtk_message_dialog_new (GTK_WINDOW (browser),
						  GTK_DIALOG_MODAL,
						  _GTK_ICON_NAME_DIALOG_QUESTION,
						  _("Could not move the files"),
						  _("Files cannot be moved to the current location, as alternative you can choose to copy them."),
						  _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
						  _("Copy"), GTK_RESPONSE_OK,
						  NULL);
		response = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);

		if (response == GTK_RESPONSE_CANCEL) {
			paste_data_free (paste_data);
			return;
		}

		paste_data->cut = FALSE;
	}

	position = -1;
	path = gth_file_selection_get_last_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
	if (path != NULL) {
		int *indices;

		indices = gtk_tree_path_get_indices (path);
		if (indices != NULL)
			position = indices[0] + 1;
		gtk_tree_path_free (path);
	}

	task = gth_copy_task_new (paste_data->file_source,
				  paste_data->destination,
				  paste_data->cut,
				  paste_data->files,
				  position);
	gth_browser_exec_task (browser, task, GTH_TASK_FLAGS_DEFAULT);

	g_object_unref (task);
	paste_data_free (paste_data);
}
Exemple #4
0
static void fx_many_item_toggled(GtkCellRendererToggle *UNUSED(cell)
		, char* path_str , gpointer data)
{
	FxMany* fxmany = (FxMany*)data;
	GtkTreeView* tree = GTK_TREE_VIEW(fxmany->tree);
	GtkTreeModel* model = gtk_tree_view_get_model(tree);
	GtkTreeView* ctree = GTK_TREE_VIEW(fxmany->selected);
	GtkTreeModel* cmodel = gtk_tree_view_get_model(ctree);
	GtkTreePath* path = gtk_tree_path_new_from_string(path_str);
	GtkTreeIter iter;
	gboolean checked , checked1;
	char* name;
	char* sipuri;
	char* uri;
	char labeltext[128];
	GdkPixbuf* pb;

	GtkTreeIter cIter;
	GtkTreeIter childiter;

	gtk_tree_model_get_iter(model , &iter , path);
	gtk_tree_model_get(model , &iter
					 , S_SIPURI_COL , &sipuri
					 , S_CHECK_COL  , &checked
					 , -1);
	checked ^= 1;

	if(checked)
	{
		if(gtk_tree_path_get_depth(path) > 1){
			gtk_tree_model_get(model , &iter
							 , S_NAME_COL   , &name
							 , S_PIXBUF_COL , &pb
							 , -1);
			gtk_tree_store_append(GTK_TREE_STORE(cmodel) , &cIter , NULL);
			gtk_tree_store_set(GTK_TREE_STORE(cmodel) , &cIter 
							 , C_PIXBUF_COL           , pb
							 , C_NAME_COL             , name
							 , C_SIPURI_COL           , sipuri
							 , -1);
			fxmany->chooseCount ++;

			free(name);
			free(sipuri);
			g_object_unref(pb);
		}else{
			if(gtk_tree_model_iter_children(model , &childiter , &iter)){
				do{
					gtk_tree_model_get(model , &childiter
									 , S_CHECK_COL  , &checked1
									 , S_NAME_COL   , &name
									 , S_SIPURI_COL , &sipuri
									 , S_PIXBUF_COL , &pb
									 , -1);
					if(!checked1){
						gtk_tree_store_append(GTK_TREE_STORE(cmodel) , &cIter , NULL);
						gtk_tree_store_set(GTK_TREE_STORE(cmodel) , &cIter 
										 , C_PIXBUF_COL           , pb
										 , C_NAME_COL             , name
										 , C_SIPURI_COL           , sipuri
										 , -1);
						fxmany->chooseCount ++;
						gtk_tree_store_set(GTK_TREE_STORE(model) , &childiter
								, S_CHECK_COL , TRUE , -1);
					}
					free(name);
					free(sipuri);
					g_object_unref(pb);
				}while(gtk_tree_model_iter_next(model , &childiter));
			}
		}
	}
	else
	{
		if(gtk_tree_path_get_depth(path) > 1){
			gtk_tree_model_get_iter_root(cmodel , &cIter);
			do{
				gtk_tree_model_get(cmodel       , &cIter 
								 , C_SIPURI_COL , &uri
								 , -1);
				if(strcmp(sipuri , uri) == 0){
					free(uri);
					break;
				}
			}while(gtk_tree_model_iter_next(cmodel , &cIter));
			gtk_tree_store_remove(GTK_TREE_STORE(cmodel) , &cIter);
			fxmany->chooseCount --;
		}else{
			if(gtk_tree_model_iter_children(model , &childiter , &iter)){
				do{
					gtk_tree_model_get(model , &childiter 
							, S_CHECK_COL , &checked1
							, S_SIPURI_COL , &sipuri , -1);

					if(!checked1)
						continue;

					gtk_tree_model_get_iter_root(cmodel , &cIter);

					do{
						gtk_tree_model_get(cmodel       , &cIter 
										 , C_SIPURI_COL , &uri
										 , -1);
						if(strcmp(sipuri , uri) == 0){
							free(uri);
							break;
						}
					}while(gtk_tree_model_iter_next(cmodel , &cIter));

					gtk_tree_store_remove(GTK_TREE_STORE(cmodel) , &cIter);
					fxmany->chooseCount --;
					gtk_tree_store_set(GTK_TREE_STORE(model) , &childiter
							, S_CHECK_COL , FALSE , -1);

					free(sipuri);

				}while(gtk_tree_model_iter_next(model , &childiter));
			}
		}
	}
	gtk_tree_store_set(GTK_TREE_STORE(model) , &iter
					 , S_CHECK_COL , checked 
					 , -1);

	gtk_tree_path_free(path);
	snprintf(labeltext, sizeof(labeltext) - 1 ,
			_("Choosed [<span color=\"red\">%d</span>] contacts, "
			"[<span color=\"red\">%d</span>] more available"),
		     fxmany->chooseCount , 10000 - fxmany->chooseCount);
	gtk_label_set_markup(GTK_LABEL(fxmany->label) , labeltext);

}
gboolean vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
{
	ViewDir *vd = data;
	GtkTreePath *tpath;
	GtkTreeViewColumn *column;
	GtkTreeIter iter;
	NodeData *nd = NULL;
	FileData *fd;

	if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
					  &tpath, &column, NULL, NULL))
		{
		GtkTreeModel *store;
		gint left_of_expander;

		store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
		gtk_tree_model_get_iter(store, &iter, tpath);
		gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
		gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);

		if (vdtree_clicked_on_expander(GTK_TREE_VIEW(widget), tpath, column, bevent->x, bevent->y, &left_of_expander))
			{
			vd->click_fd = NULL;

			/* clicking this region should automatically reveal an expander, if necessary
			 * treeview bug: the expander will not expand until a button_motion_event highlights it.
			 */
			if (bevent->button == MOUSE_BUTTON_LEFT &&
			    !left_of_expander &&
			    !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath))
				{
				vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd);

				fd = (nd) ? nd->fd : NULL;
				if (fd && islink(fd->path))
					{
					vdtree_icon_set_by_iter(vd, &iter, vd->pf->link);
					}
				else
					{
					vdtree_icon_set_by_iter(vd, &iter, vd->pf->open);
					}
				}

			gtk_tree_path_free(tpath);
			return FALSE;
			}

		gtk_tree_path_free(tpath);
		}

	vd->click_fd = (nd) ? nd->fd : NULL;
	vd_color_set(vd, vd->click_fd, TRUE);

	if (bevent->button == MOUSE_BUTTON_RIGHT)
		{
		vd->popup = vd_pop_menu(vd, vd->click_fd);
		gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL,
			       bevent->button, bevent->time);
		}

	return (bevent->button != MOUSE_BUTTON_LEFT);
}
// Create a new bus from the current selection
static void create_bus_button_clicked (GtkWidget *widget, gpointer data)
  {
  int row_type = -1 ;
  bus_layout_D *dialog = (bus_layout_D *)data ;
  GList *llTreeRefs = NULL, *llItr = NULL ;
  GtkTreeStore *ts = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tview))) ;
  GtkTreeIter itrBus, itr, itrSrc, itrSrcParent ;
  GtkTreeRowReference *refBus = NULL, *refSrcParent = NULL ;
  GtkTreePath *tp = NULL, *tpSrcParent = NULL ;

  llTreeRefs = get_selected_refs (gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->tview))) ;

  if (NULL == llTreeRefs) return ;

  if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itr,
    tp = gtk_tree_row_reference_get_path (llTreeRefs->data)))
    {
    gtk_tree_path_free (tp) ;
    return ;
    }

  gtk_tree_model_get (GTK_TREE_MODEL (ts), &itr, BUS_LAYOUT_MODEL_COLUMN_TYPE, &row_type, -1) ;

  gtk_tree_path_free (tp) ;

  gtk_tree_store_prepend (ts, &itrBus, NULL) ;
  gtk_tree_store_set (ts, &itrBus,
    BUS_LAYOUT_MODEL_COLUMN_ICON, (row_type & ROW_TYPE_INPUT) ? QCAD_STOCK_BUS_INPUT : QCAD_STOCK_BUS_OUTPUT,
    BUS_LAYOUT_MODEL_COLUMN_NAME, _("Untitled Bus"),
    BUS_LAYOUT_MODEL_COLUMN_TYPE, (row_type & ROW_TYPE_INPUT) ? ROW_TYPE_BUS_INPUT : ROW_TYPE_BUS_OUTPUT,
    BUS_LAYOUT_MODEL_COLUMN_INDEX, -1, -1) ;

  refBus = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &itrBus)) ;
  gtk_tree_path_free (tp) ;

  for (llItr = g_list_last (llTreeRefs) ; llItr != NULL ; llItr = llItr->prev)
    {
    if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrBus, tp = gtk_tree_row_reference_get_path (refBus)))
      {
      gtk_tree_path_free (tp) ;

      gtk_tree_store_append (ts, &itr, &itrBus) ;

      if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrSrc, tp = gtk_tree_row_reference_get_path (llItr->data)))
        swap_model_iters_contents (GTK_TREE_MODEL (ts), &itrSrc, &itr) ;
      gtk_tree_path_free (tp) ;

      if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrSrc, tp = gtk_tree_row_reference_get_path (llItr->data)))
        {
        if (gtk_tree_path_get_depth (tp) > 1)
          {
          if (gtk_tree_path_up (tpSrcParent = gtk_tree_path_copy (tp)))
            refSrcParent = (1 == gtk_tree_model_path_n_children (GTK_TREE_MODEL (ts), tpSrcParent)) ?
              gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tpSrcParent) : NULL ;

          gtk_tree_path_free (tpSrcParent) ;
          }
        }
      gtk_tree_path_free (tp) ;

      gtk_tree_row_reference_free (llItr->data) ;

      // Remove cell from old location
      gtk_tree_store_remove (ts, &itrSrc) ;

      // The bus that owned the row we just moved has become empty - delete it
      if (NULL != refSrcParent)
        {
        tpSrcParent = gtk_tree_row_reference_get_path (refSrcParent) ;

        if (gtk_tree_model_get_iter (GTK_TREE_MODEL (ts), &itrSrcParent, tpSrcParent))
          gtk_tree_store_remove (ts, &itrSrcParent) ;

        gtk_tree_path_free (tpSrcParent) ;
        gtk_tree_row_reference_free (refSrcParent) ;
        refSrcParent = NULL ;
        }
      }
    else
      gtk_tree_path_free (tp) ;
    }

  gtk_tree_selection_select_path (gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->tview)), tp = gtk_tree_row_reference_get_path (refBus)) ;

  gtk_tree_path_free (tp) ;
  gtk_tree_row_reference_free (refBus) ;
  g_list_free (llTreeRefs) ;
  }
// This callback is responsible for enabling/disabling the appropriate buttons depending on
// the contents of the selection
static void tree_view_selection_changed (GtkTreeSelection *sel, gpointer data)
  {
  bus_layout_D *dialog = (bus_layout_D *)data ;
  gboolean bSomethingSelected = FALSE ;
  gboolean bBusSelected = FALSE ;
  gboolean bSelectionIsFromBus = FALSE ;
  gboolean bFirstSelected = FALSE ;
  gboolean bLastSelected = FALSE ;
  gboolean bFirstBusSelected = TRUE ;
  gboolean bLastBusSelected = TRUE ;
  GtkTreePath *tpSelBus = NULL, *tp = NULL ;
  GtkTreeModel *tm = NULL ;
  int icChildren = -1, Nix ;

  tm = gtk_tree_view_get_model (gtk_tree_selection_get_tree_view (sel)) ;

  if ((bSelectionIsFromBus = (NULL != (tpSelBus = get_selection_bus (sel, &bSomethingSelected)))))
    if (!(bFirstSelected = bLastSelected = bBusSelected = whole_bus_selected_p (sel, tm, tpSelBus)))
      if ((icChildren = gtk_tree_model_path_n_children (tm, tpSelBus)) > 0)
        {
        gtk_tree_path_down (tp = gtk_tree_path_copy (tpSelBus)) ;
        bFirstSelected = gtk_tree_selection_path_is_selected (sel, tp) ;
        for (Nix = 1 ; Nix < icChildren ; Nix++) gtk_tree_path_next (tp) ;
        bLastSelected = gtk_tree_selection_path_is_selected (sel, tp) ;
        gtk_tree_path_free (tp) ;
        }

  if (bSelectionIsFromBus)
    determine_first_or_last_bus (tm, tpSelBus, &bFirstBusSelected, &bLastBusSelected) ;

  gtk_widget_set_sensitive (dialog->btnCreateBus, bSomethingSelected && !bBusSelected) ;
  gtk_widget_set_sensitive (dialog->btnDeleteBus, bSelectionIsFromBus) ;
  gtk_widget_set_sensitive (dialog->btnMoveBusUp, bSelectionIsFromBus && !bFirstBusSelected) ;
  gtk_widget_set_sensitive (dialog->btnMoveBusDown, bSelectionIsFromBus && !bLastBusSelected) ;
  gtk_widget_set_sensitive (dialog->btnMoveCellsUp, bSelectionIsFromBus && !bFirstSelected) ;
  gtk_widget_set_sensitive (dialog->btnMoveCellsDown, bSelectionIsFromBus && !bLastSelected) ;
  gtk_widget_set_sensitive (dialog->lblBusName, bSelectionIsFromBus) ;
  gtk_widget_set_sensitive (dialog->txtBusName, bSelectionIsFromBus) ;

  // Fill in the text box with the name of the bus
  if (bSelectionIsFromBus)
    {
    GtkTreeIter itr ;
    char *psz = NULL ;

    if (gtk_tree_model_get_iter (tm, &itr, tpSelBus))
      {
      gtk_tree_model_get (tm, &itr, BUS_LAYOUT_MODEL_COLUMN_NAME, &psz, -1) ;

      bus_name_entry_set_quiet (dialog->txtBusName, TRUE, TRUE) ;
      gtk_entry_set_text (GTK_ENTRY (dialog->txtBusName), psz) ;
      bus_name_entry_set_quiet (dialog->txtBusName, FALSE, TRUE) ;

      g_free (psz) ;
      }
    }

  if (NULL != (tp = g_object_get_data (G_OBJECT (gtk_tree_selection_get_tree_view (sel)), "tpBus")))
    gtk_tree_path_free (tp) ;
  g_object_set_data (G_OBJECT (gtk_tree_selection_get_tree_view (sel)), "tpBus", tpSelBus) ;
  }
static void
bg_colors_source_add_color (BgColorsSource               *self,
                            GnomeDesktopThumbnailFactory *thumb_factory,
                            GtkListStore                 *store,
                            const char                   *color,
                            GtkTreeRowReference         **ret_row_ref)
{
  CcBackgroundItemFlags flags;
  CcBackgroundItem *item;
  GdkPixbuf *pixbuf;
  cairo_surface_t *surface;
  int scale_factor;
  int thumbnail_height, thumbnail_width;
  GtkTreeIter iter;

  thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (self));
  thumbnail_width = bg_source_get_thumbnail_width (BG_SOURCE (self));

  item = cc_background_item_new (NULL);
  flags = CC_BACKGROUND_ITEM_HAS_PCOLOR |
          CC_BACKGROUND_ITEM_HAS_SCOLOR |
          CC_BACKGROUND_ITEM_HAS_SHADING |
          CC_BACKGROUND_ITEM_HAS_PLACEMENT |
          CC_BACKGROUND_ITEM_HAS_URI;
  /* It does have a URI, it's "none" */

  g_object_set (G_OBJECT (item),
                "uri", "file:///" DATADIR "/gnome-control-center/pixmaps/noise-texture-light.png",
                "primary-color", color,
                "secondary-color", color,
                "shading", G_DESKTOP_BACKGROUND_SHADING_SOLID,
                "placement", G_DESKTOP_BACKGROUND_STYLE_WALLPAPER,
                "flags", flags,
                NULL);
  cc_background_item_load (item, NULL);

  /* insert the item into the liststore */
  scale_factor = bg_source_get_scale_factor (BG_SOURCE (self));
  pixbuf = cc_background_item_get_thumbnail (item,
                                             thumb_factory,
                                             thumbnail_width, thumbnail_height,
                                             scale_factor);
  surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
  gtk_list_store_insert_with_values (store, &iter, 0,
                                     0, surface,
                                     1, item,
                                     -1);

  if (ret_row_ref)
    {
      GtkTreePath *path;

      path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
      *ret_row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
      gtk_tree_path_free (path);
    }

  cairo_surface_destroy (surface);
  g_object_unref (pixbuf);
  g_object_unref (item);
}
Exemple #9
0
static void
file_view_select_from_iter (AnjutaFileView* view, GtkTreeIter iter)
{
	AnjutaFileViewPrivate* priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view);

	GtkTreeModelSort* model_sort;
	gboolean valid;
	GtkTreeIter sort_iter;
	GFile* file;

	model_sort = GTK_TREE_MODEL_SORT (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));

	do
	{
		gboolean is_dummy, is_dir;

		gtk_tree_model_get (GTK_TREE_MODEL (priv->model), &iter,
							COLUMN_FILE, &file, COLUMN_DUMMY, &is_dummy,
							COLUMN_IS_DIR, &is_dir, -1);

		if (is_dummy)
			break;

		if (g_file_equal (priv->pending_selected_file, file))
		{
			file_view_select_iter (view, iter);
			break;
		}

		else if (g_file_has_prefix (priv->pending_selected_file, file))
		{
			if (is_dir)
			{
				GtkTreePath *path = NULL;

				gtk_tree_model_sort_convert_child_iter_to_iter (model_sort, &sort_iter, &iter);
				path = gtk_tree_model_get_path (GTK_TREE_MODEL (model_sort), &sort_iter);

				if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path))
				{
					GtkTreeIter parent = iter;
					valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (priv->model), &iter, &parent);
					gtk_tree_path_free (path);
				}
				else
				{
					gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
					gtk_tree_path_free (path);
					break;
				}
			}
			else
			{
				file_view_select_iter (view, iter);
				break;
			}
		}
		else
			valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->model), &iter);

		g_clear_object (&file);

	} while (valid);

	if (file)
		g_object_unref (file);
}
void
cell_edited_callback(GtkCellRendererText *cell,
                     const gchar         *path_string,
                     gchar               *new_text,
                     gpointer data)
{
	GtkTreeModel *model = (GtkTreeModel *)data;
	GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
	GtkTreeIter iter;
	GtkTreeIter iter_name;

	gchar *col_name;
	char new_ip[20];

	strcpy(new_ip, new_text);

	gint column =
	        GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cell), "column"));

	gtk_tree_model_get_iter(model, &iter, path);

	gtk_tree_model_get_iter(model, &iter_name, path);
	gtk_tree_model_get(model, &iter_name, 0, &col_name, -1);

	switch (column) {
	case COLUMN_VALUE:
	{
		uint i = 0, index_offset = 0;
		gchar *old_text;

		gtk_tree_model_get(model, &iter, column, &old_text, -1);

		if (0 == strcmp(col_name, pktgen_ethernet_fields[3]))
			if ((atoi(new_text) > 4096) || (atoi(new_text) < 1)) {
				GtkWidget *dialog;
				dialog =
				        gtk_message_dialog_new(GTK_WINDOW(stream_window),
				                               GTK_DIALOG_DESTROY_WITH_PARENT,
				                               GTK_MESSAGE_INFO,
				                               GTK_BUTTONS_OK,
				                               "Invalid VLAN Id! It should be [1-4095]");
				gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen");
				gtk_dialog_run(GTK_DIALOG(dialog));
				gtk_widget_destroy(dialog);
				return;
			}

		if ((0 ==
		     strcmp(col_name,
		            pktgen_ipv4_fields[9])) ||
		    (0 == strcmp(col_name, pktgen_ipv4_fields[10])) )
			if (!validate_ip_address(new_ip)) {
				GtkWidget *dialog;
				dialog =
				        gtk_message_dialog_new(GTK_WINDOW(stream_window),
				                               GTK_DIALOG_DESTROY_WITH_PARENT,
				                               GTK_MESSAGE_INFO,
				                               GTK_BUTTONS_OK,
				                               "The given IP is not a valid IP address!");
				gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen");
				gtk_dialog_run(GTK_DIALOG(dialog));
				gtk_widget_destroy(dialog);
				return;
			}

		/* Validate the MAC address */
		if ((0 ==
		     strcmp(col_name,
		            pktgen_ethernet_fields[0])) ||
		    (0 == strcmp(col_name, pktgen_ethernet_fields[1])) ) {
			if (12 == strlen(new_text)) {
				gchar *ch;
				for (i = 0; i < strlen(new_text); i++) {
					ch = (new_text + i);

					if ((*ch >= 'a' &&
					     *ch <= 'f') ||
					    (*ch >= 'A' &&
					     *ch <= 'F') ||
					    (*ch >= '0' && *ch <= '9'))
						continue;
					else {
						GtkWidget *dialog;
						dialog = gtk_message_dialog_new(
						                GTK_WINDOW(stream_window),
						                GTK_DIALOG_DESTROY_WITH_PARENT,
						                GTK_MESSAGE_INFO,
						                GTK_BUTTONS_OK,
						                "Please input only hex values[0-9][a-f], special characters are not allowed!");
						gtk_window_set_title(GTK_WINDOW(dialog),
						                     "Pktgen");
						gtk_dialog_run(GTK_DIALOG(dialog));
						gtk_widget_destroy(dialog);

						return;
					}
				}
			} else {
				GtkWidget *dialog;
				dialog =
				        gtk_message_dialog_new(GTK_WINDOW(stream_window),
				                               GTK_DIALOG_DESTROY_WITH_PARENT,
				                               GTK_MESSAGE_INFO,
				                               GTK_BUTTONS_OK,
				                               "Please input 6 bytes of MAC address in hex pattern [e.g. 012345abcdef]");
				gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen");
				gtk_dialog_run(GTK_DIALOG(dialog));
				gtk_widget_destroy(dialog);

				return;
			}
		}
		if ((0 !=
		     strcmp(old_text,
		            "<auto>")) &&
		    (0 !=
		     strcmp(old_text,
		            "IPv4")) && (0 != strcmp(old_text, "UDP")) ) {
			g_free(old_text);

			i = gtk_tree_path_get_indices(path)[0];

			switch (gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)))
			{
			case 0:
				index_offset = 0;
				break;

			case 1:
				index_offset = 4;
				break;

			case 2:
				index_offset = 15;
				break;
			}

			g_free(g_array_index(packet_info, protocol,
			                     (i + index_offset)).value);
			g_array_index(packet_info, protocol,
			              (i + index_offset)).value = g_strdup(new_text);

			gtk_list_store_set(GTK_LIST_STORE(model), &iter, column,
			                   g_array_index(packet_info,
			                                 protocol,
			                                 (i + index_offset)).value, -1);
		} else {
			GtkWidget *dialog;
			dialog =
			        gtk_message_dialog_new(GTK_WINDOW(stream_window),
			                               GTK_DIALOG_DESTROY_WITH_PARENT,
			                               GTK_MESSAGE_INFO,
			                               GTK_BUTTONS_OK,
			                               "Auto generated values can not be modified!");
			gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen");
			gtk_dialog_run(GTK_DIALOG(dialog));
			gtk_widget_destroy(dialog);
		}
	}
	break;
	}

	gtk_tree_path_free(path);
}
/*
 * Selects a single price in the price tree view.  The price
 * tree must be in single selection mode.
 */
void
gnc_tree_view_price_set_selected_price (GncTreeViewPrice *view,
                                        GNCPrice *price)
{
    GtkTreeModel *model, *f_model, *s_model;
    GtkTreePath *path, *f_path, *s_path, *parent_path;
    GtkTreeSelection *selection;

    ENTER("view %p, price %p", view, price);

    /* Clear any existing selection. */
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
    gtk_tree_selection_unselect_all (selection);

    if (price == NULL)
        return;

    s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
    f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
    model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (f_model));

    path = gnc_tree_model_price_get_path_from_price (GNC_TREE_MODEL_PRICE(model), price);
    if (path == NULL)
    {
        LEAVE("get_path_from_price failed");
        return;
    }
    debug_path(DEBUG, path);

    f_path = gtk_tree_model_filter_convert_child_path_to_path (GTK_TREE_MODEL_FILTER (f_model),
             path);
    gtk_tree_path_free(path);
    if (f_path == NULL)
    {
        LEAVE("no filter path");
        return;
    }
    debug_path(DEBUG, f_path);

    s_path = gtk_tree_model_sort_convert_child_path_to_path (GTK_TREE_MODEL_SORT (s_model),
             f_path);
    gtk_tree_path_free(f_path);
    if (s_path == NULL)
    {
        LEAVE("no sort path");
        return;
    }

    /* gtk_tree_view requires that a row be visible before it can be selected */
    parent_path = gtk_tree_path_copy (s_path);
    if (gtk_tree_path_up (parent_path))
    {
        /* This function is misnamed.  It expands the actual item
         * specified, not the path to the item specified. I.E. It expands
         * one level too many, thus the get of the parent. */
        gtk_tree_view_expand_to_path(GTK_TREE_VIEW(view), parent_path);
    }
    gtk_tree_path_free(parent_path);

    gtk_tree_selection_select_path (selection, s_path);
    gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(view), s_path, NULL, FALSE, 0.0, 0.0);
    debug_path(LEAVE, s_path);
    gtk_tree_path_free(s_path);
}
Exemple #12
0
static void
fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
{
    FMListModel *model;
    FileEntry *file_entry;
    CajaFile *file;
    char *str;
    GdkPixbuf *icon, *rendered_icon;
    GIcon *gicon, *emblemed_icon, *emblem_icon;
    CajaIconInfo *icon_info;
    GEmblem *emblem;
    GList *emblem_icons, *l;
    int icon_size;
    CajaZoomLevel zoom_level;
    CajaFile *parent_file;
    char *emblems_to_ignore[3];
    int i;
    CajaFileIconFlags flags;

    model = (FMListModel *)tree_model;

    g_return_if_fail (model->details->stamp == iter->stamp);
    g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));

    file_entry = g_sequence_get (iter->user_data);
    file = file_entry->file;

    switch (column)
    {
    case FM_LIST_MODEL_FILE_COLUMN:
        g_value_init (value, CAJA_TYPE_FILE);

        g_value_set_object (value, file);
        break;
    case FM_LIST_MODEL_SUBDIRECTORY_COLUMN:
        g_value_init (value, CAJA_TYPE_DIRECTORY);

        g_value_set_object (value, file_entry->subdirectory);
        break;
    case FM_LIST_MODEL_SMALLEST_ICON_COLUMN:
    case FM_LIST_MODEL_SMALLER_ICON_COLUMN:
    case FM_LIST_MODEL_SMALL_ICON_COLUMN:
    case FM_LIST_MODEL_STANDARD_ICON_COLUMN:
    case FM_LIST_MODEL_LARGE_ICON_COLUMN:
    case FM_LIST_MODEL_LARGER_ICON_COLUMN:
    case FM_LIST_MODEL_LARGEST_ICON_COLUMN:
        g_value_init (value, GDK_TYPE_PIXBUF);

        if (file != NULL)
        {
            zoom_level = fm_list_model_get_zoom_level_from_column_id (column);
            icon_size = caja_get_icon_size_for_zoom_level (zoom_level);

            flags = CAJA_FILE_ICON_FLAGS_USE_THUMBNAILS |
                    CAJA_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
                    CAJA_FILE_ICON_FLAGS_USE_MOUNT_ICON_AS_EMBLEM;
            if (model->details->drag_view != NULL)
            {
                GtkTreePath *path_a, *path_b;

                gtk_tree_view_get_drag_dest_row (model->details->drag_view,
                                                 &path_a,
                                                 NULL);
                if (path_a != NULL)
                {
                    path_b = gtk_tree_model_get_path (tree_model, iter);

                    if (gtk_tree_path_compare (path_a, path_b) == 0)
                    {
                        flags |= CAJA_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
                    }

                    gtk_tree_path_free (path_a);
                    gtk_tree_path_free (path_b);
                }
            }

            gicon = caja_file_get_gicon (file, flags);

            /* render emblems with GEmblemedIcon */
            parent_file = caja_file_get_parent (file);
            i = 0;
            emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_TRASH;
            if (parent_file) {
            	if (!caja_file_can_write (parent_file)) {
                    emblems_to_ignore[i++] = CAJA_FILE_EMBLEM_NAME_CANT_WRITE;
            	}
            	caja_file_unref (parent_file);
            }
            emblems_to_ignore[i++] = NULL;

            emblem = NULL;
            emblem_icons = caja_file_get_emblem_icons (file,
            					       emblems_to_ignore);

            if (emblem_icons != NULL) {
                emblem_icon = emblem_icons->data;
                emblem = g_emblem_new (emblem_icon);
                emblemed_icon = g_emblemed_icon_new (gicon, emblem);

                g_object_unref (emblem);

            	for (l = emblem_icons->next; l != NULL; l = l->next) {
            	    emblem_icon = l->data;
            	    emblem = g_emblem_new (emblem_icon);
            	    g_emblemed_icon_add_emblem
            	        (G_EMBLEMED_ICON (emblemed_icon), emblem);

                    g_object_unref (emblem);
            	}

                g_list_free_full (emblem_icons, g_object_unref);

            	g_object_unref (gicon);
            	gicon = emblemed_icon;
            }

            icon_info = caja_icon_info_lookup (gicon, icon_size);
            icon = caja_icon_info_get_pixbuf_at_size (icon_info, icon_size);

            g_object_unref (icon_info);
            g_object_unref (gicon);

            if (model->details->highlight_files != NULL &&
                    g_list_find_custom (model->details->highlight_files,
                                        file, (GCompareFunc) caja_file_compare_location))
            {
                rendered_icon = eel_gdk_pixbuf_render (icon, 1, 255, 255, 0, 0);

                if (rendered_icon != NULL)
                {
                    g_object_unref (icon);
                    icon = rendered_icon;
                }
            }

            g_value_set_object (value, icon);
            g_object_unref (icon);
        }
        break;
    case FM_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
        g_value_init (value, G_TYPE_BOOLEAN);

        g_value_set_boolean (value, file != NULL && caja_file_can_rename (file));
        break;
    default:
        if (column >= FM_LIST_MODEL_NUM_COLUMNS || column < FM_LIST_MODEL_NUM_COLUMNS + model->details->columns->len)
        {
            CajaColumn *caja_column;
            GQuark attribute;
            caja_column = model->details->columns->pdata[column - FM_LIST_MODEL_NUM_COLUMNS];

            g_value_init (value, G_TYPE_STRING);
            g_object_get (caja_column,
                          "attribute_q", &attribute,
                          NULL);
            if (file != NULL)
            {
                str = caja_file_get_string_attribute_with_default_q (file,
                        attribute);
                g_value_take_string (value, str);
            }
            else if (attribute == attribute_name_q)
            {
                if (file_entry->parent->loaded)
                {
                    g_value_set_string (value, _("(Empty)"));
                }
                else
                {
                    g_value_set_string (value, _("Loading..."));
                }
            }
        }
        else
        {
            g_assert_not_reached ();
        }
    }
}
Exemple #13
0
void
fm_list_model_file_changed (FMListModel *model, CajaFile *file,
                            CajaDirectory *directory)
{
    FileEntry *parent_file_entry;
    GtkTreeIter iter;
    GtkTreePath *path, *parent_path;
    GSequenceIter *ptr;
    int pos_before, pos_after, length, i, old;
    int *new_order;
    gboolean has_iter;
    GSequence *files;

    ptr = lookup_file (model, file, directory);
    if (!ptr)
    {
        return;
    }


    pos_before = g_sequence_iter_get_position (ptr);

    g_sequence_sort_changed (ptr, fm_list_model_file_entry_compare_func, model);

    pos_after = g_sequence_iter_get_position (ptr);

    if (pos_before != pos_after)
    {
        /* The file moved, we need to send rows_reordered */

        parent_file_entry = ((FileEntry *)g_sequence_get (ptr))->parent;

        if (parent_file_entry == NULL)
        {
            has_iter = FALSE;
            parent_path = gtk_tree_path_new ();
            files = model->details->files;
        }
        else
        {
            has_iter = TRUE;
            fm_list_model_ptr_to_iter (model, parent_file_entry->ptr, &iter);
            parent_path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
            files = parent_file_entry->files;
        }

        length = g_sequence_get_length (files);
        new_order = g_new (int, length);
        /* Note: new_order[newpos] = oldpos */
        for (i = 0, old = 0; i < length; ++i)
        {
            if (i == pos_after)
            {
                new_order[i] = pos_before;
            }
            else
            {
                if (old == pos_before)
                    old++;
                new_order[i] = old++;
            }
        }

        gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model),
                                       parent_path, has_iter ? &iter : NULL, new_order);

        gtk_tree_path_free (parent_path);
        g_free (new_order);
    }
Exemple #14
0
gboolean
fm_list_model_add_file (FMListModel *model, CajaFile *file,
                        CajaDirectory *directory)
{
    GtkTreeIter iter;
    GtkTreePath *path;
    FileEntry *file_entry;
    GSequenceIter *ptr, *parent_ptr;
    GSequence *files;
    gboolean replace_dummy;
    GHashTable *parent_hash;

    parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map,
                                      directory);
    if (parent_ptr)
    {
        file_entry = g_sequence_get (parent_ptr);
        ptr = g_hash_table_lookup (file_entry->reverse_map, file);
    }
    else
    {
        file_entry = NULL;
        ptr = g_hash_table_lookup (model->details->top_reverse_map, file);
    }

    if (ptr != NULL)
    {
        g_warning ("file already in tree (parent_ptr: %p)!!!\n", parent_ptr);
        return FALSE;
    }

    file_entry = g_new0 (FileEntry, 1);
    file_entry->file = caja_file_ref (file);
    file_entry->parent = NULL;
    file_entry->subdirectory = NULL;
    file_entry->files = NULL;

    files = model->details->files;
    parent_hash = model->details->top_reverse_map;

    replace_dummy = FALSE;

    if (parent_ptr != NULL)
    {
        file_entry->parent = g_sequence_get (parent_ptr);
        /* At this point we set loaded. Either we saw
         * "done" and ignored it waiting for this, or we do this
         * earlier, but then we replace the dummy row anyway,
         * so it doesn't matter */
        file_entry->parent->loaded = 1;
        parent_hash = file_entry->parent->reverse_map;
        files = file_entry->parent->files;
        if (g_sequence_get_length (files) == 1)
        {
            GSequenceIter *dummy_ptr = g_sequence_get_iter_at_pos (files, 0);
            FileEntry *dummy_entry = g_sequence_get (dummy_ptr);
            if (dummy_entry->file == NULL)
            {
                /* replace the dummy loading entry */
                model->details->stamp++;
                g_sequence_remove (dummy_ptr);

                replace_dummy = TRUE;
            }
        }
    }


    file_entry->ptr = g_sequence_insert_sorted (files, file_entry,
                      fm_list_model_file_entry_compare_func, model);

    g_hash_table_insert (parent_hash, file, file_entry->ptr);

    iter.stamp = model->details->stamp;
    iter.user_data = file_entry->ptr;

    path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
    if (replace_dummy)
    {
        gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
    }
    else
    {
        gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
    }

    if (caja_file_is_directory (file))
    {
        file_entry->files = g_sequence_new ((GDestroyNotify)file_entry_free);

        add_dummy_row (model, file_entry);

        gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model),
                                              path, &iter);
    }
    gtk_tree_path_free (path);

    return TRUE;
}
static void
update_thumbnail_popup_process (GtkWidget *widget, GdkEventMotion *event)
{
    //g_message ("Doing %s, event = %p", __func__, event);

    static gboolean witn = FALSE;	/* "Was in thumbnail".  */
    static GtkTreePath *otp = NULL;
    static GtkTreeViewColumn *otc = NULL;
    static GTimer *hover_timer = NULL;
    if ( hover_timer == NULL ) {
        hover_timer = g_timer_new ();
    }

    /* Fos some crazy reason, drawing the popup image changes the result
    of in_thumbnail (I suspect because gdk is reusing event
    structures in some strange way).  So memorize in_thumbnail up
    front.  */
    // Also, this assertion should pass, but doesn't... synthesizing
    // motion events is apparently a bit harder than I realized.
    // g_assert (event->type == GDK_MOTION_NOTIFY);
    //g_message ("event x: %lf, event y: %lf", event->x, event->y); 
    gboolean event_in_thumbnail = in_thumbnail (widget, event);

    /* Hover time in milliseconds required before a popup image is
    displayed.  */
    const gint hover_time = 70;

    if ( !witn && in_output_thumbnail (widget, event) ) {
        witn = TRUE;
        otp = thumbnail_path (widget, event);
        g_assert (gtk_tree_path_get_depth (otp) == 1);
        otc = thumbnail_column (widget, event);
        g_timer_start (hover_timer);
        //g_message ("Adding timeout from !with && in_output_thumbnail");
        fake_motion_signal_args_t *fmsa = g_new (fake_motion_signal_args_t, 1);
        fmsa->widget = widget;
        fmsa->event = event;      
        fmsa->is_valid = TRUE;
        g_timeout_add (hover_time, (GSourceFunc) emit_fake_motion_signal, fmsa);
    }

    if ( witn && in_output_thumbnail (widget, event) ) {
        //g_message ("in_thumbnail: %d", in_thumbnail (widget, event));
        GtkTreePath *ctp = thumbnail_path (widget, event);
        g_assert (gtk_tree_path_get_depth (ctp) == 1);
        GtkTreeViewColumn *ctc = thumbnail_column (widget, event);
        if ( gtk_tree_path_compare (ctp, otp) == 0 && ctc == otc ) {
            /* Sometimes the timeout handler seems to go off a bit before
            timer has measured the correct amount of time, so we add a
            small margin here.  */
            const gint slop_time = 5;
            const gint seconds_to_mseconds_factor = 1000;
            /* If we hover for this long or longer, we should show the popup.  */
            if ( g_timer_elapsed (hover_timer, NULL) * seconds_to_mseconds_factor 
                >= hover_time - slop_time) {
                    //g_message ("elapsed time: %lf\n", g_timer_elapsed (hover_timer, NULL));
                    //g_message ("Do popup!!!");
                    //g_message ("in_thumbnail: %d", in_thumbnail (widget, event));
                    GdkRegion *tr = thumbnail_region (widget, event);
                    //g_message ("bpw in_thumbnail: %d", in_thumbnail (widget, event));
                    //g_message ("widget: %p", widget);
                    GdkWindow *popup_window = draw_popup_image (widget, ctp, ctc, tr);
                    //g_message ("apw in_thumbnail: %d", in_thumbnail (widget, event));
                    //g_message ("widget: %p", widget);
                    /* We don't want continuous redrawing of the popup, so we
                    disable the handler that triggers it until the popup is
                    removed.  */

                    if (popup_window)
                    {
                        guint signal_id = g_signal_lookup ("motion-notify-event",
                            GTK_WIDGET_TYPE (widget));
                        gulong handler_id 
                            = g_signal_handler_find (widget,
                            G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC
                            | G_SIGNAL_MATCH_DATA,
                            signal_id,
                            (GQuark) 0,
                            NULL,
                            completed_files_list_motion_notify_event_handler,
                            NULL);
                        g_assert (handler_id != 0);
                        g_signal_handler_block (widget, handler_id);
                        /* We want to get rid of the popup window as soon as the user
                        moves the mouse outside of the original thumbnail
                        space.  */
                        maybe_clear_popup_image_args.popup = popup_window;
                        maybe_clear_popup_image_args.tree_view = GTK_TREE_VIEW (widget);
                        if ( maybe_clear_popup_image_args.thumbnail_region != NULL ) {
                            gdk_region_destroy (maybe_clear_popup_image_args.thumbnail_region);
                        }
                        //g_message ("in_thumbnail: %d", in_thumbnail (widget, event));
                        maybe_clear_popup_image_args.thumbnail_region = tr;
                        g_signal_connect (widget, "motion-notify-event", 
                            G_CALLBACK (maybe_clear_popup_image), 
                            &maybe_clear_popup_image_args);
                        //g_message ("in_thumbnail: %d", in_thumbnail (widget, event));
                    }
                } 
            else {
                gtk_tree_path_free (ctp);
            }
        }
        else {
            gtk_tree_path_free (otp);
            otp = ctp;
            otc = ctc;
            g_timer_start (hover_timer);
            //g_message ("Adding timeout from 'different thumbnails'");
            fake_motion_signal_args_t *fmsa = g_new (fake_motion_signal_args_t, 1);
            fmsa->widget = widget;
            fmsa->event = event;      
            fmsa->is_valid = TRUE;
            g_timeout_add (hover_time, (GSourceFunc) emit_fake_motion_signal, fmsa);
        }
    }

    if ( witn && !event_in_thumbnail ) {
        //g_message ("in_thumbnail: %d", in_thumbnail (widget, event));
        //g_message ("Setting witn false");
        witn = FALSE;
    }
}
Exemple #16
0
static void bar_pane_keywords_menu_popup(GtkWidget *widget, PaneKeywordsData *pkd, gint x, gint y)
{
	GtkWidget *menu;
	GtkWidget *item;
	GtkWidget *submenu;
        GtkTreeViewDropPosition pos;

        if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath);
        pkd->click_tpath = NULL;
	gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(pkd->keyword_treeview), x, y, &pkd->click_tpath, &pos);

	menu = popup_menu_short_lived();

	menu_item_add_stock(menu, _("Add keyword"), GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd);

	menu_item_add_divider(menu);

	menu_item_add(menu, _("Add keyword to all selected images"), G_CALLBACK(bar_pane_keywords_add_to_selected_cb), pkd);

	menu_item_add_divider(menu);

	if (pkd->click_tpath)
		{
		/* for the entry */
		gchar *text;
		gchar *mark;
		gint i;

		GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview));

		GtkTreeIter iter;
                gtk_tree_model_get_iter(model, &iter, pkd->click_tpath);
		gchar *name;

		gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name,
						 FILTER_KEYWORD_COLUMN_MARK, &mark, -1);

		text = g_strdup_printf(_("Hide \"%s\""), name);
		menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_hide_cb), pkd);
		g_free(text);

		submenu = gtk_menu_new();
		for (i = 0; i < FILEDATA_MARKS_SIZE; i++)
			{
			text = g_strdup_printf(_("Mark %d"), i + 1);
			item = menu_item_add(submenu, text, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd);
			g_object_set_data(G_OBJECT(item), "mark", GINT_TO_POINTER(i + 1));
			g_free(text);
			}
		text = g_strdup_printf(_("Connect \"%s\" to mark"), name);
		item = menu_item_add(menu, text, NULL, NULL);
		gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
		g_free(text);

		menu_item_add_divider(menu);

		text = g_strdup_printf(_("Edit \"%s\""), name);
		menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_edit_dialog_cb), pkd);
		g_free(text);
		text = g_strdup_printf(_("Remove \"%s\""), name);
		menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd);
		g_free(text);


		if (mark && mark[0])
			{
			text = g_strdup_printf(_("Disconnect \"%s\" from mark %s"), name, mark);
			menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd);
			g_free(text);
			}

		menu_item_add_divider(menu);
		g_free(mark);
		g_free(name);
		}
	/* for the pane */


	menu_item_add(menu, _("Expand checked"), G_CALLBACK(bar_pane_keywords_expand_checked_cb), pkd);
	menu_item_add(menu, _("Collapse unchecked"), G_CALLBACK(bar_pane_keywords_collapse_unchecked_cb), pkd);
	menu_item_add(menu, _("Hide unchecked"), G_CALLBACK(bar_pane_keywords_hide_unchecked_cb), pkd);
	menu_item_add(menu, _("Show all"), G_CALLBACK(bar_pane_keywords_show_all_cb), pkd);

	submenu = gtk_menu_new();
	item = menu_item_add(menu, _("On any change"), NULL, NULL);
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);

	menu_item_add_check(submenu, _("Expand checked"), pkd->expand_checked, G_CALLBACK(bar_pane_keywords_expand_checked_toggle_cb), pkd);
	menu_item_add_check(submenu, _("Collapse unchecked"), pkd->collapse_unchecked, G_CALLBACK(bar_pane_keywords_collapse_unchecked_toggle_cb), pkd);
	menu_item_add_check(submenu, _("Hide unchecked"), pkd->hide_unchecked, G_CALLBACK(bar_pane_keywords_hide_unchecked_toggle_cb), pkd);

	gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME);
}
static void DialogToBusLayout (bus_layout_D *dialog, BUS_LAYOUT *bus_layout)
  {
  GtkTreeModel *tm = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tview)) ;
  int Nix ;
  int icTopLevel = gtk_tree_model_iter_n_children (tm, NULL), icCells = -1 ;
  GtkTreePath *tp = NULL, *tpCells = NULL ;
  GtkTreeIter itr ;
  int Nix1, idxCell = -1 ;
  int row_type ;
  EXP_ARRAY *cell_list = NULL ;
  BUS *bus ;

  // destroy all buses before adding the new ones
  for (Nix = bus_layout->buses->icUsed - 1 ; Nix > -1 ; Nix--)
    {
    exp_array_free (exp_array_index_1d (bus_layout->buses, BUS, Nix).cell_indices) ;
    g_free (exp_array_index_1d (bus_layout->buses, BUS, Nix).pszName) ;
    }
  exp_array_remove_vals (bus_layout->buses, 1, 0, bus_layout->buses->icUsed) ;

  // Since we've destroyed all buses, no cells are members of any bus any longer
  for (Nix = 0 ; Nix < bus_layout->inputs->icUsed ; Nix++)
    exp_array_index_1d (bus_layout->inputs, BUS_LAYOUT_CELL, Nix).bIsInBus = FALSE ;
  for (Nix = 0 ; Nix < bus_layout->outputs->icUsed ; Nix++)
    exp_array_index_1d (bus_layout->outputs, BUS_LAYOUT_CELL, Nix).bIsInBus = FALSE ;

  if (icTopLevel > 0)
    {
    tp = gtk_tree_path_new_first () ;
    for (Nix = 0 ; Nix < icTopLevel ; Nix++, gtk_tree_path_next (tp))
      {
      if (gtk_tree_model_get_iter (tm, &itr, tp))
        {
        gtk_tree_model_get (tm, &itr, BUS_LAYOUT_MODEL_COLUMN_TYPE, &row_type, -1) ;
        if (ROW_TYPE_BUS & row_type)
          {
          exp_array_1d_insert_vals (bus_layout->buses, NULL, 1, -1) ;
          bus = &(exp_array_index_1d (bus_layout->buses, BUS, bus_layout->buses->icUsed - 1)) ;
          gtk_tree_model_get (tm, &itr, BUS_LAYOUT_MODEL_COLUMN_NAME, &(bus->pszName), -1) ;
          if (ROW_TYPE_INPUT & row_type)
            {
            bus->bus_function = QCAD_CELL_INPUT ;
            cell_list = bus_layout->inputs ;
            }
          else
            {
            bus->bus_function = QCAD_CELL_OUTPUT ;
            cell_list = bus_layout->outputs ;
            }
          bus->cell_indices = exp_array_new (sizeof (int), 1) ;
          if ((icCells = gtk_tree_model_iter_n_children (tm, &itr)) > 0)
            {
            gtk_tree_path_down (tpCells = gtk_tree_path_copy (tp)) ;

            for (Nix1 = 0 ; Nix1 < icCells ; Nix1++, gtk_tree_path_next (tpCells))
              if (gtk_tree_model_get_iter (tm, &itr, tpCells))
                {
                gtk_tree_model_get (tm, &itr, BUS_LAYOUT_MODEL_COLUMN_INDEX, &idxCell, -1) ;
                exp_array_1d_insert_vals (bus->cell_indices, &idxCell, 1, -1) ;
                // Flag this cell in the master cell list as a member of some bus
                exp_array_index_1d (cell_list, BUS_LAYOUT_CELL, idxCell).bIsInBus = TRUE ;
                }
            gtk_tree_path_free (tpCells) ;
            }
          }
        }
      }
    gtk_tree_path_free (tp) ;
    }
  }
Exemple #18
0
static void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *context,
					  gint x, gint y,
					  GtkSelectionData *selection_data, guint info,
					  guint time, gpointer data)
{
	PaneKeywordsData *pkd = data;
	GtkTreePath *tpath = NULL;
        GtkTreeViewDropPosition pos;
	GtkTreeModel *model;

	GtkTreeModel *keyword_tree;
	gboolean src_valid = FALSE;
	GList *new_keywords = NULL;
	GList *work;

	/* iterators for keyword_tree */
	GtkTreeIter src_kw_iter;
	GtkTreeIter dest_kw_iter;
	GtkTreeIter new_kw_iter;

	g_signal_stop_emission_by_name(tree_view, "drag_data_received");

	model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view));
	keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model));

	gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos);
	gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), NULL, pos);

	switch (info)
		{
		case TARGET_APP_KEYWORD_PATH:
			{
			GList *path = *(gpointer *)gtk_selection_data_get_data(selection_data);
			src_valid = keyword_tree_get_iter(keyword_tree, &src_kw_iter, path);
			string_list_free(path);
			break;
			}
		default:
			new_keywords = string_to_keywords_list((gchar *)gtk_selection_data_get_data(selection_data));
			break;
		}

	if (tpath)
		{
		GtkTreeIter dest_iter;
                gtk_tree_model_get_iter(model, &dest_iter, tpath);
		gtk_tree_path_free(tpath);
		gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &dest_kw_iter, &dest_iter);

		if (src_valid && gtk_tree_store_is_ancestor(GTK_TREE_STORE(keyword_tree), &src_kw_iter, &dest_kw_iter))
			{
			/* can't move to it's own child */
			return;
			}

		if (src_valid && keyword_compare(keyword_tree, &src_kw_iter, &dest_kw_iter) == 0)
			{
			/* can't move to itself */
			return;
			}

		if ((pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) &&
		    !gtk_tree_model_iter_has_child(keyword_tree, &dest_kw_iter))
			{
			/* the node has no children, all keywords can be added */
			gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &dest_kw_iter);
			}
		else
			{
			if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, &dest_kw_iter))
				{
				/* the keyword can't be moved if the same name already exist */
				return;
				}
			if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, &dest_kw_iter, &new_keywords))
				{
				/* the keywords can't be added if the same name already exist */
				return;
				}

			switch (pos)
				{
				case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
				case GTK_TREE_VIEW_DROP_BEFORE:
					gtk_tree_store_insert_before(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter);
					break;
				case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
				case GTK_TREE_VIEW_DROP_AFTER:
					gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter);
					break;
				}
			}

		}
	else
		{
		if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, NULL))
			{
			/* the keyword can't be moved if the same name already exist */
			return;
			}
		if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, NULL, &new_keywords))
			{
			/* the keywords can't be added if the same name already exist */
			return;
			}
		gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL);
		}


	if (src_valid)
		{
		keyword_move_recursive(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &src_kw_iter);
		}

	work = new_keywords;
	while (work)
		{
		gchar *keyword = work->data;
		keyword_set(GTK_TREE_STORE(keyword_tree), &new_kw_iter, keyword, TRUE);
		work = work->next;

		if (work)
			{
			GtkTreeIter add;
			gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &new_kw_iter);
			new_kw_iter = add;
			}
		}
	string_list_free(new_keywords);
	bar_keyword_tree_sync(pkd);
}
// Implements the selection constraints for the available cells tree view
static gboolean select_cell_row_p (GtkTreeSelection *sel, GtkTreeModel *tm, GtkTreePath *tp, gboolean bSelStatus, gpointer data)
  {
  int Nix ;
  static gboolean bIgnore = FALSE ;
  int this_row_type = -1 ;
  GtkTreeIter itr ;

  if (bIgnore) return TRUE ;

  if (!gtk_tree_model_get_iter (tm, &itr, tp)) return FALSE ;

  gtk_tree_model_get (tm, &itr, BUS_LAYOUT_MODEL_COLUMN_TYPE, &this_row_type, -1) ;

  if (this_row_type & ROW_TYPE_BUS)
    {
    GtkTreePath *tpNew = NULL ;
    int icChildren = gtk_tree_model_iter_n_children (tm, &itr) ;
    int x, y ;
    GdkModifierType mask ;

    if (bSelStatus)
      {
      bIgnore = TRUE ;
      gtk_tree_selection_unselect_path (sel, tp) ;
      bIgnore = FALSE ;
      }

    gtk_tree_view_expand_row (gtk_tree_selection_get_tree_view (sel), tp, TRUE) ;

    if (icChildren > 0)
      {
      // I should be able to programmatically simulate a "click" event, because its meaning depends
      // on whether Ctrl or Shift are held down.  I should not have to reproduce that behaviour here,
      // because it may change in the future. I need to simulate a "click" event because I would like to
      // implement the following: Clicking on a bus is equivalent to clicking on all its inputs
      gdk_window_get_pointer (GTK_WIDGET (gtk_tree_selection_get_tree_view (sel))->window, &x, &y, &mask) ;

      gtk_tree_path_down (tpNew = gtk_tree_path_copy (tp)) ;

      bSelStatus = gtk_tree_selection_path_is_selected (sel, tpNew) ;

      for (Nix = 0 ; Nix < icChildren ; Nix++, gtk_tree_path_next (tpNew))
        if ((mask & GDK_CONTROL_MASK))
          {
          if (bSelStatus)
            gtk_tree_selection_unselect_path (sel, tpNew) ;
          else
            gtk_tree_selection_select_path (sel, tpNew) ;
          }
        else
          gtk_tree_selection_select_path (sel, tpNew) ;

      gtk_tree_path_free (tpNew) ;
      }
    return FALSE ;
    }
  else
  if (this_row_type & ROW_TYPE_CELL)
    {
    if (!bSelStatus)
      {
      DESELECT_DIFFERENT_CELLS_STRUCT ddcs = {NULL, 0} ;

      ddcs.sel = sel ;
      ddcs.row_type = this_row_type ;

      gtk_tree_selection_selected_foreach (sel, deselect_other_type_of_cells, &ddcs) ;
      }
    }

  return TRUE ;
  }
Exemple #20
0
static void bar_pane_keywords_edit_destroy_cb(GtkWidget *widget, gpointer data)
{
	ConfDialogData *cdd = data;
	gtk_tree_path_free(cdd->click_tpath);
	g_free(cdd);
}
// start helpers
static void swap_buses (GtkTreeModel *tm, GtkTreeSelection *sel, bus_layout_D *dialog, GtkTreePath *tpSrc, GtkTreePath *tpDst)
  {
  int Nix ;
  GtkTreeIter itr ;
  SWAP_BUSES_STRUCT src, dst ;
  SWAP_BUSES_STRUCT *min = NULL, *max = NULL ;
  EXP_ARRAY *ar_bSelSrc = NULL, *ar_bSelDst = NULL ;
  gboolean bDstExpanded = TRUE ;

  if (!gtk_tree_model_get_iter (tm, &(src.itr), tpSrc)) return ;
  src.tp = gtk_tree_path_copy (tpSrc) ;
  src.icChildren = gtk_tree_model_iter_n_children (tm, &(src.itr)) ;

  if (!gtk_tree_model_get_iter (tm, &(dst.itr), tpDst))
    {
    gtk_tree_path_free (src.tp) ;
    return ;
    }
  dst.tp = gtk_tree_path_copy (tpDst) ;
  dst.icChildren = gtk_tree_model_iter_n_children (tm, &(dst.itr)) ;

  if (dst.icChildren < src.icChildren)
    {
    min = &dst ;
    max = &src ;
    }
  else
    {
    min = &src ;
    max = &dst ;
    }

  bDstExpanded = gtk_tree_view_row_expanded (gtk_tree_selection_get_tree_view (sel), dst.tp) ;

  g_signal_handlers_block_matched (G_OBJECT (sel), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, (gpointer)tree_view_selection_changed, NULL) ;

  for (Nix = 0 ; Nix < max->icChildren - min->icChildren ; Nix++)
    gtk_tree_store_append (GTK_TREE_STORE (tm), &itr, &(min->itr)) ;

  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  ar_bSelSrc = exp_array_new (sizeof (gboolean), 1) ;
  ar_bSelDst = exp_array_new (sizeof (gboolean), 1) ;
  exp_array_1d_insert_vals (ar_bSelSrc, NULL, max->icChildren, 0) ;
  exp_array_1d_insert_vals (ar_bSelDst, NULL, max->icChildren, 0) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    exp_array_index_1d (ar_bSelSrc, gboolean, Nix) =
      gtk_tree_selection_path_is_selected (sel, src.tp) ;
    exp_array_index_1d (ar_bSelDst, gboolean, Nix) =
      gtk_tree_selection_path_is_selected (sel, dst.tp) ;

    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;
  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    if (exp_array_index_1d (ar_bSelDst, gboolean, Nix))
      gtk_tree_view_expand_to_path (gtk_tree_selection_get_tree_view (sel), src.tp) ;

    if (exp_array_index_1d (ar_bSelSrc, gboolean, Nix))
      gtk_tree_view_expand_to_path (gtk_tree_selection_get_tree_view (sel), dst.tp) ;

    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;
  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    swap_model_paths_contents (tm, src.tp, dst.tp) ;
    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;
  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    GTK_TREE_SELECTION_SET_PATH_SELECTED (sel, src.tp, exp_array_index_1d (ar_bSelDst, gboolean, Nix)) ;
    GTK_TREE_SELECTION_SET_PATH_SELECTED (sel, dst.tp, exp_array_index_1d (ar_bSelSrc, gboolean, Nix)) ;
    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;

  swap_model_paths_contents (tm, src.tp, dst.tp) ;

  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < min->icChildren ; Nix++)
    gtk_tree_path_next (max->tp) ;
  if (gtk_tree_model_get_iter (tm, &itr, max->tp))
    while (gtk_tree_store_remove (GTK_TREE_STORE (tm), &itr)) ;

  if (!bDstExpanded)
    {
    for (Nix = 0 ; Nix < ar_bSelDst->icUsed ; Nix++)
      if (exp_array_index_1d (ar_bSelDst, gboolean, Nix))
        break ;

    if (Nix == ar_bSelDst->icUsed)
      if (gtk_tree_path_up (src.tp))
        gtk_tree_view_collapse_row (gtk_tree_selection_get_tree_view (sel), src.tp) ;
    }

swap_buses_quit:

  exp_array_free (ar_bSelSrc) ;
  exp_array_free (ar_bSelDst) ;
  gtk_tree_path_free (src.tp) ;
  gtk_tree_path_free (dst.tp) ;
  g_signal_handlers_unblock_matched (G_OBJECT (sel), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, (gpointer)tree_view_selection_changed, NULL) ;
  tree_view_selection_changed (sel, dialog) ;
  }
Exemple #22
0
gint
export_contacts_to_file(gchar *filename, gboolean header, GUI *appGUI) {

GtkTreePath *sort_path, *filter_path, *path;
gint i, j, a, b, c, e, n, m, max_field, exported;
gchar *text;
GtkTreeIter iter;
FILE *filehandle;
guint32 date;
gchar tmpbuf[BUFFER_SIZE];
gchar tmp_buffer_1[BUFFER_SIZE], tmp_buffer_2[BUFFER_SIZE];

    exported = 0;

    if (utl_gui_check_overwrite_file (filename, appGUI->cnt->export_window, appGUI) != 0) {
        return -1;
    }

    for(max_field = CONTACTS_NUM_COLUMNS-1; max_field >= 0; --max_field) {
        if(config.export_fields[max_field] == '+') break;
    }
    if (max_field == -1) {
        max_field = CONTACTS_NUM_COLUMNS-1;
    }

    filehandle = g_fopen (filename, "w");
    if(filehandle) {

        if (config.export_format == EXPORT_TO_XHTML) {
            fprintf(filehandle, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
            fprintf(filehandle, "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
            fprintf(filehandle, "<head>\n");
            fprintf(filehandle, "\t<title>Contact List</title>\n");
            fprintf(filehandle, "\t<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n");
            fprintf(filehandle, "\t<meta name=\"generator\" content=\"OSMO - http://clay.ll.pl/osmo\" />\n");
            fprintf(filehandle, "\t<style type=\"text/css\">\n");
            fprintf(filehandle, "\t\tbody { color:black; background-color:white; }\n");
            fprintf(filehandle, "\t\ta { color:#0000ff; }\n");
            fprintf(filehandle, "\t\ta:visited { color:#000055; }\n");
            fprintf(filehandle, "\t\ttable { border-collapse:collapse; }\n");
            fprintf(filehandle, "\t\ttr.header { background-color:#c0c0c0; }\n");
            fprintf(filehandle, "\t\ttr.evenrow { background-color:#f0f0f0; }\n");
            fprintf(filehandle, "\t\ttr.oddrow { background-color:#fafafa; }\n");
            fprintf(filehandle, "\t\tth, td { border:1px solid #555555; padding:3px; }\n");
            fprintf(filehandle, "\t</style>\n");
            fprintf(filehandle, "</head>\n\n");
            fprintf(filehandle, "<body>\n\n");
            fprintf(filehandle, "<h1>Contact List</h1>\n\n");

            fprintf(filehandle, "<table>\n");

            fprintf(filehandle, "<tr class=\"header\">\n");

            for(i=0; i < CONTACTS_NUM_COLUMNS; i++) {
                if(config.export_fields[i] == '+') {
                    fprintf(filehandle, "\t<th>");

                    if (appGUI->cnt->contact_fields_tags_name[i*2] != NULL) {
                        for(a=b=0; a < strlen(appGUI->cnt->contact_fields_tags_name[i*2]); a++) {
                            if(appGUI->cnt->contact_fields_tags_name[i*2][a] == ' ') {
                                tmpbuf[b] = '\0';
                                strcat(tmpbuf, "&nbsp;");
                                b += 6;
                            } else {
                                tmpbuf[b++] = appGUI->cnt->contact_fields_tags_name[i*2][a];
                            }
                        }
                        tmpbuf[b] = '\0';
                        fprintf(filehandle, "%s", tmpbuf);
                    }

                    fprintf(filehandle, "</th>\n");
                }
            }

            fprintf(filehandle, "</tr>\n\n");
        }

        j = 0;
        sort_path = gtk_tree_path_new_first ();

        while (gtk_tree_model_get_iter (GTK_TREE_MODEL(appGUI->cnt->contacts_list_store), &iter, sort_path) == TRUE) {

            if (sort_path != NULL) {

                filter_path = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT(appGUI->cnt->contacts_sort), sort_path);

                if (filter_path != NULL) {

                    path = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER(appGUI->cnt->contacts_filter), filter_path);

                    if (path != NULL) {

                        gtk_tree_model_get_iter (GTK_TREE_MODEL(appGUI->cnt->contacts_list_store), &iter, path);

                        if (config.export_format == EXPORT_TO_XHTML) {
                            if(j & 1) {
                                fprintf(filehandle, "<tr class=\"evenrow\">\n");
                            } else {
                                fprintf(filehandle, "<tr class=\"oddrow\">\n");
                            }
                        } else if (config.export_format == EXPORT_TO_CSV && header == TRUE && j == 0) {

                            for(i=n=0; i < CONTACTS_NUM_COLUMNS; i++) {
                                if (i != COLUMN_PHOTO && i != COLUMN_ID && config.export_fields[i] == '+') {
                                    n++;
                                }
                            }
                            for(i=m=0; i < CONTACTS_NUM_COLUMNS; i++) {
                                if (i != COLUMN_PHOTO && i != COLUMN_ID && config.export_fields[i] == '+') {
                                    fprintf(filehandle, "%s", appGUI->cnt->contact_fields_tags_name[i*2]);
                                    if (m != n-1) {
                                        fprintf(filehandle, ",");
                                    }
                                    m++;
                                }
                            }
                            fprintf(filehandle, "\n");
                        }

                        for(i=0; i < CONTACTS_NUM_COLUMNS; i++) {

                            if(config.export_fields[i] == '+') {

                                if (i == COLUMN_BIRTH_DAY_DATE || i == COLUMN_NAME_DAY_DATE) {
                                    gtk_tree_model_get (GTK_TREE_MODEL(appGUI->cnt->contacts_list_store), &iter, i, &date, -1);
                                    if (date == 0) {
                                        text = NULL;
                                    } else {
                                        if (i == COLUMN_BIRTH_DAY_DATE) {
                                            text = g_strdup((const gchar *)julian_to_str(date, DATE_FULL, config.override_locale_settings));
                                        } else {
                                            text = g_strdup((const gchar *)julian_to_str(date, DATE_NAME_DAY, config.override_locale_settings));
                                        }
                                    }
                                } else {
                                    gtk_tree_model_get (GTK_TREE_MODEL(appGUI->cnt->contacts_list_store), &iter, i, &text, -1);
                                }

                                if (config.export_format == EXPORT_TO_XHTML) {
                                    fprintf(filehandle, "\t<td>");

                                    if (text != NULL) {

                                        for(a=b=0; a < strlen(text); a++) {
                                            if(text[a] == ' ') {
                                                tmpbuf[b] = '\0';
                                                strcat(tmpbuf, "&nbsp;");
                                                b += 6;
                                            } else {
                                                tmpbuf[b++] = text[a];
                                            }
                                        }
                                        tmpbuf[b] = '\0';

                                        switch (i) {
                                            case COLUMN_EMAIL_1:
                                            case COLUMN_EMAIL_2:
                                            case COLUMN_EMAIL_3:
                                            case COLUMN_EMAIL_4:
                                                fprintf(filehandle, "<a href=\"mailto:%s\">%s</a>", tmpbuf, tmpbuf);
                                                break;
                                            case COLUMN_WWW_1:
                                            case COLUMN_WWW_2:
                                            case COLUMN_WWW_3:
                                            case COLUMN_WWW_4:
                                            case COLUMN_BLOG:
                                                fprintf(filehandle, "<a href=\"%s\">%s</a>", tmpbuf, tmpbuf);
                                                break;
                                            default:
                                                fprintf(filehandle, "%s", tmpbuf);
                                        }
                                        g_free(text);
                                    }

                                    fprintf(filehandle, "</td>\n");

                                } else {
                                    /* CSV */

                                    if (text != NULL) {

                                        /* 1 */

                                        for(a = b = e = 0; a < strlen(text); a++) {
                                            if(text[a]=='"') {
                                                b = 1;
                                            }
                                            if(text[a]=='\n') {
                                                e = 1;              /* found new line */
                                            }
                                        }

                                        c = a = 0;

                                        if (b) {
                                            tmp_buffer_1[c++] = '"';
                                        }

                                        do {
                                            if(text[a]=='"') {
                                                tmp_buffer_1[c++] = '"';
                                            }
                                            tmp_buffer_1[c++] = text[a];
                                            a++;
                                        } while (text[a]!='\0');

                                        if(b) {
                                            tmp_buffer_1[c++] = '"';
                                        }
                                        tmp_buffer_1[c] = '\0';

                                        /* 2 */

                                        for(a = b = 0; a < strlen(tmp_buffer_1); a++) {
                                            if(tmp_buffer_1[a]==',') {
                                                b = 1;
                                            }
                                        }

                                        c = a = 0;

                                        if (b) {
                                            tmp_buffer_2[c++] = '"';
                                        }

                                        do {
                                            tmp_buffer_2[c++] = tmp_buffer_1[a];
                                            a++;
                                        } while (tmp_buffer_1[a]!='\0');

                                        if (b) {
                                            tmp_buffer_2[c++] = '"';
                                        }
                                        tmp_buffer_2[c] = '\0';

                                        if (e) {
                                            fprintf(filehandle, "\"%s\"", tmp_buffer_2);
                                        } else {
                                            fprintf(filehandle, "%s", tmp_buffer_2);
                                        }

                                        g_free(text);
                                    }

                                    if (i != max_field) {
                                        fprintf(filehandle, ",");
                                    }

                                }

                            }
                        }

                        if (config.export_format == EXPORT_TO_XHTML) {
                            fprintf(filehandle, "</tr>\n\n");
                        } else {
                            /* CSV */
                            fprintf(filehandle, "\n");
                        }

                        j++;
                        exported++;
                        gtk_tree_path_free(path);

                    }

                    gtk_tree_path_free(filter_path);
                }

            }

            gtk_tree_path_next (sort_path);
        }

        if (config.export_format == EXPORT_TO_XHTML) {
            fprintf(filehandle, "</table>\n");

            fprintf(filehandle, "</body>\n");
            fprintf(filehandle, "</html>\n");
        }

        fclose(filehandle);

    } else {

        utl_gui_create_dialog(GTK_MESSAGE_ERROR, _("Cannot create file."), GTK_WINDOW(appGUI->cnt->export_window));
        return -1;
    }

    return exported;
}
static void vdtree_add_by_data(ViewDir *vd, FileData *fd, GtkTreeIter *parent)
{
	GtkTreeStore *store;
	GtkTreeIter child;
	NodeData *nd;
	GdkPixbuf *pixbuf;
	NodeData *end;
	GtkTreeIter empty;
	gchar *link = NULL;

	if (!fd) return;

	if (access_file(fd->path, R_OK | X_OK))
		{
		if (islink(fd->path))
			{
			pixbuf = vd->pf->link;
			}
		else
			{
			pixbuf = vd->pf->close;
			}
		}
	else
		{
		pixbuf = vd->pf->deny;
		}

	nd = g_new0(NodeData, 1);
	nd->fd = fd;
	nd->version = fd->version;
	nd->expanded = FALSE;
	nd->last_update = time(NULL);

	if (islink(fd->path))
		{
		link = realpath(fd->path, NULL);
		}
	else
		{
		link = NULL;
		}

	store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)));
	gtk_tree_store_append(store, &child, parent);
	gtk_tree_store_set(store, &child, DIR_COLUMN_POINTER, nd,
					 DIR_COLUMN_ICON, pixbuf,
					 DIR_COLUMN_NAME, nd->fd->name,
					 DIR_COLUMN_LINK, link,
					 DIR_COLUMN_COLOR, FALSE, -1);

	/* all nodes are created with an "empty" node, so that the expander is shown
	 * this is removed when the child is populated */
	end = g_new0(NodeData, 1);
	end->fd = NULL;
	end->expanded = TRUE;

	gtk_tree_store_append(store, &empty, &child);
	gtk_tree_store_set(store, &empty, DIR_COLUMN_POINTER, end,
					  DIR_COLUMN_NAME, "empty", -1);

	if (parent)
		{
		NodeData *pnd;
		GtkTreePath *tpath;

		gtk_tree_model_get(GTK_TREE_MODEL(store), parent, DIR_COLUMN_POINTER, &pnd, -1);
		tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent);
		if (options->tree_descend_subdirs &&
		    gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath) &&
		    !nd->expanded)
			{
			vdtree_populate_path_by_iter(vd, &child, FALSE, vd->dir_fd);
			}
		gtk_tree_path_free(tpath);
		}

	g_free(link);
}
Exemple #24
0
 inline void operator()(GtkTreePath *path)
 { gtk_tree_path_free(path); }
Exemple #25
0
static void
roster_view_gtk_update_groups (RosterViewGtk *view,
                               GtkTreeIter *heap_iter)
{
  GtkTreeModel *model = NULL;
  GtkTreePath *path = NULL;
  GtkTreeIter iter;

  GSList *existing_group = NULL;

  int timeout = 0;
  gboolean go_on = FALSE;
  gchar *name = NULL;

  model = GTK_TREE_MODEL (view->priv->store);

  if (gtk_tree_model_iter_nth_child (model, &iter, heap_iter, 0)) {

    do {

      // If this node has children, see if it must be
      // folded or unfolded
      if (gtk_tree_model_iter_has_child (model, &iter)) {

        update_offline_count (view, &iter);
        gtk_tree_model_get (model, &iter,
                            COLUMN_GROUP_NAME, &name, -1);
        if (name) {

          if (view->priv->folded_groups)
            existing_group = g_slist_find_custom (view->priv->folded_groups,
                                                  name,
                                                  (GCompareFunc) g_ascii_strcasecmp);

          path = gtk_tree_model_get_path (model, heap_iter);
          gtk_tree_view_expand_row (view->priv->tree_view, path, FALSE);
          gtk_tree_path_free (path);

          path = gtk_tree_model_get_path (model, &iter);
          if (path) {

            if (existing_group == NULL) {
              if (!gtk_tree_view_row_expanded (view->priv->tree_view, path)) {
                gtk_tree_view_expand_row (view->priv->tree_view, path, TRUE);
              }
            }
            else {
              if (gtk_tree_view_row_expanded (view->priv->tree_view, path)) {
                gtk_tree_view_collapse_row (view->priv->tree_view, path);
              }
            }

            gtk_tree_path_free (path);
          }

          go_on = gtk_tree_model_iter_next (model, &iter);
        }

        g_free (name);
      }
      // else remove the node (no children)
      else {

        gtk_tree_model_get (GTK_TREE_MODEL (view->priv->store), &iter,
                            COLUMN_TIMEOUT, &timeout,
                            -1);
        go_on = gtk_tree_store_remove (view->priv->store, &iter);
      }
    } while (go_on);
  }
}
Exemple #26
0
bool
sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
                  girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);

  if(zathura->ui.index == NULL) {
    return false;
  }

  GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
  GtkTreePath *path;

  gtk_tree_view_get_cursor(tree_view, &path, NULL);
  if (path == NULL) {
    return false;
  }

  GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
  GtkTreeIter   iter;
  GtkTreeIter   child_iter;

  gboolean is_valid_path = TRUE;

  switch(argument->n) {
    case UP:
      if (gtk_tree_path_prev(path) == FALSE) {
        /* For some reason gtk_tree_path_up returns TRUE although we're not
         * moving anywhere. */
        is_valid_path = gtk_tree_path_up(path) && (gtk_tree_path_get_depth(path) > 0);
      } else { /* row above */
        while(gtk_tree_view_row_expanded(tree_view, path)) {
          gtk_tree_model_get_iter(model, &iter, path);
          /* select last child */
          gtk_tree_model_iter_nth_child(model, &child_iter, &iter,
                                        gtk_tree_model_iter_n_children(model, &iter)-1);
          gtk_tree_path_free(path);
          path = gtk_tree_model_get_path(model, &child_iter);
        }
      }
      break;
    case COLLAPSE:
      if (gtk_tree_view_collapse_row(tree_view, path) == FALSE
          && gtk_tree_path_get_depth(path) > 1) {
        gtk_tree_path_up(path);
        gtk_tree_view_collapse_row(tree_view, path);
      }
      break;
    case DOWN:
      if (gtk_tree_view_row_expanded(tree_view, path) == TRUE) {
        gtk_tree_path_down(path);
      } else {
        do {
          gtk_tree_model_get_iter(model, &iter, path);
          if (gtk_tree_model_iter_next(model, &iter)) {
            gtk_tree_path_free(path);
            path = gtk_tree_model_get_path(model, &iter);
            break;
          }
        } while((is_valid_path = (gtk_tree_path_get_depth(path) > 1))
                && gtk_tree_path_up(path));
      }
      break;
    case EXPAND:
      if (gtk_tree_view_expand_row(tree_view, path, FALSE)) {
        gtk_tree_path_down(path);
      }
      break;
    case EXPAND_ALL:
      gtk_tree_view_expand_all(tree_view);
      break;
    case COLLAPSE_ALL:
      gtk_tree_view_collapse_all(tree_view);
      gtk_tree_path_free(path);
      path = gtk_tree_path_new_first();
      gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
      break;
    case SELECT:
      cb_index_row_activated(tree_view, path, NULL, zathura);
      gtk_tree_path_free(path);
      return false;
  }

  if (is_valid_path) {
    gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
  }

  gtk_tree_path_free(path);

  return false;
}
Exemple #27
0
static void search_tree(gpointer data)
{
	struct search_info *info = data;
	GtkTreePath *path;
	GtkTreeViewColumn *col;
	GtkTreeModel *model;
	TraceViewStore *store;
	GtkTreeIter iter;
	GtkEntry *entry = GTK_ENTRY(info->entry);
	GtkComboBox *col_combo = GTK_COMBO_BOX(info->column);
	GtkComboBox *sel_combo = GTK_COMBO_BOX(info->selection);
	const gchar *title;
	const gchar *search_text;
	gint col_num;
	gint sel;
	gint search_val;
	gint start_row;
	gboolean found = FALSE;
	gint i = 0;

	col_num = gtk_combo_box_get_active(col_combo);
	sel = gtk_combo_box_get_active(sel_combo);

	if (col_num >= TRACE_VIEW_STORE_N_COLUMNS)
		return;

	search_text = gtk_entry_get_text(entry);
	if (!search_text || !strlen(search_text))
		return;

	col = gtk_tree_view_get_column(info->treeview, col_num);
	if (!col)
		return;

	title = gtk_tree_view_column_get_title(col);
	if (!title)
		return;

	model = gtk_tree_view_get_model(info->treeview);
	if (!model)
		return;

	store = TRACE_VIEW_STORE(model);

	if (!trace_view_store_visible_rows(store))
		return;

	start_row = trace_view_get_selected_row(GTK_WIDGET(info->treeview));
	if (start_row < 0)
		start_row = 0;

	if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, start_row))
		return;

	trace_set_cursor(GDK_WATCH);
	trace_freeze_all();

	search_val = atoi(search_text);
	while (gtk_tree_model_iter_next(model, &iter)) {
		/* Needed to process the cursor change */
		if (!(i++ & ((1 << 5)-1)))
		    gtk_main_iteration_do(FALSE);

		found = test_row(model, &iter, sel, col_num, search_val, search_text);
		if (found)
			break;
	}
	trace_unfreeze_all();
	trace_put_cursor();

	if (!found) {
		GtkResponseType ret;
		gint pages = trace_view_store_get_pages(store);
		gint page = trace_view_store_get_page(store);

		if (page < pages) {
			ret = trace_dialog(NULL, TRACE_GUI_ASK,
					   "Not found on this page\n"
					   "Search next pages?");
			if (ret == GTK_RESPONSE_YES)
				search_next_pages(info->treeview, store, sel,
						  col_num, search_val, search_text);
			return;
		}
		trace_dialog(NULL, TRACE_GUI_INFO, "Not found");
		return;
	}

	path = gtk_tree_model_get_path(model, &iter);
	select_row_from_path(info->treeview, path);
	gtk_tree_path_free(path);
}
Exemple #28
0
static gint
on_contact_clicked (GtkWidget *tree_view,
		    GdkEventButton *event,
		    gpointer data)
{
  GtkTreePath *path = NULL;
  GtkTreeIter iter;
  GtkTreeModel *model = NULL;

  if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view),
				     (gint) event->x, (gint) event->y,
				     &path, NULL, NULL, NULL)) {

    model
      = gtk_tree_view_get_model (BOOK_VIEW_GTK (data)->priv->tree_view);

    if (gtk_tree_model_get_iter (model, &iter, path)) {

      Ekiga::Contact *contact = NULL;
      gtk_tree_model_get (model, &iter,
			  COLUMN_CONTACT_POINTER, &contact,
			  -1);

      if (contact != NULL) {

	if (event->type == GDK_BUTTON_PRESS && event->button == 3) {

	  Ekiga::TemporaryMenuBuilder temp;
	  MenuBuilderGtk builder;

	  BOOK_VIEW_GTK (data)->priv->book->populate_menu (temp);
	  contact->populate_menu (builder);

	  if (!temp.empty ()) {

	    builder.add_separator ();
	    temp.populate_menu (builder);
	  }

	  if (!builder.empty ()) {

	    gtk_widget_show_all (builder.menu);
	    gtk_menu_popup (GTK_MENU (builder.menu), NULL, NULL,
			    NULL, NULL, event->button, event->time);
	    g_signal_connect (builder.menu, "hide",
			      G_CALLBACK (g_object_unref),
			      (gpointer) builder.menu);
	  }
	  g_object_ref_sink (G_OBJECT (builder.menu));
	} else if (event->type == GDK_2BUTTON_PRESS) {

	  Ekiga::TriggerMenuBuilder builder;

	  contact->populate_menu (builder);
	}
      }
    }
    gtk_tree_path_free (path);
  }

  return TRUE;
}
Exemple #29
0
static void
new_folder_dialog_response_cb (GtkWidget *dialog,
			       int        response_id,
			       gpointer   user_data)
{
	NewFolderData *data = user_data;
	char          *name;
	GFile         *folder;
	GError        *error = NULL;

	if (response_id != GTK_RESPONSE_OK) {
		new_folder_data_free (data);
		gtk_widget_destroy (dialog);
		return;
	}

	name = gth_request_dialog_get_normalized_text (GTH_REQUEST_DIALOG (dialog));
	if (_g_utf8_all_spaces (name)) {
		g_free (name);
		gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, _("No name specified"));
		return;
	}

	if (g_regex_match_simple ("/", name, 0, 0)) {
		char *message;

		message = g_strdup_printf (_("Invalid name. The following characters are not allowed: %s"), "/");
		gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, message);

		g_free (message);
		g_free (name);

		return;
	}

	folder = g_file_get_child_for_display_name (data->parent, name, &error);
	if ((folder != NULL) && g_file_make_directory (folder, NULL, &error)) {
		GList       *list;
		GtkWidget   *folder_tree;
		GtkTreePath *path;

		list = g_list_prepend (NULL, folder);
		gth_monitor_folder_changed (gth_main_get_default_monitor (),
					    data->parent,
					    list,
					    GTH_MONITOR_EVENT_CREATED);

		folder_tree = gth_browser_get_folder_tree (data->browser);
		path = gth_folder_tree_get_path (GTH_FOLDER_TREE (folder_tree), data->parent);
		gth_folder_tree_expand_row (GTH_FOLDER_TREE (folder_tree), path, FALSE);

		gtk_tree_path_free (path);
		g_list_free (list);
	}

	if (error != NULL) {
		if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
			gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, _("Name already used"));
		else
			gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, error->message);
		g_clear_error (&error);
	}
	else {
		gth_browser_load_location (data->browser, folder);
		new_folder_data_free (data);
		gtk_widget_destroy (dialog);
	}

	g_object_unref (folder);
}
Exemple #30
0
static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event,
				    MimeView *mimeview)
{
	GtkTreeView *treeview = GTK_TREE_VIEW(widget);
	MimeInfo *partinfo;

	if (!event) return FALSE;

	if (event->button == 2 || event->button == 3) {
		GtkTreePath *path;

		if (!gtk_tree_view_get_path_at_pos(treeview, event->x, event->y,
						   &path, NULL, NULL, NULL))
			return FALSE;
		gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
		gtk_tree_path_free(path);
	}

	if (event->button == 2 ||
	    (event->button == 1 && event->type == GDK_2BUTTON_PRESS)) {
		/* call external program for image, audio or html */
		mimeview_launch(mimeview);
	} else if (event->button == 3) {
		partinfo = mimeview_get_selected_part(mimeview);
		if (partinfo && (partinfo->mime_type == MIME_TEXT ||
				 partinfo->mime_type == MIME_TEXT_HTML ||
				 partinfo->mime_type == MIME_MESSAGE_RFC822 ||
				 partinfo->mime_type == MIME_IMAGE ||
				 partinfo->mime_type == MIME_MULTIPART))
			menu_set_sensitive(mimeview->popupfactory,
					   "/Display as text", FALSE);
		else
			menu_set_sensitive(mimeview->popupfactory,
					   "/Display as text", TRUE);
		if (partinfo &&
		    partinfo->mime_type == MIME_APPLICATION_OCTET_STREAM)
			menu_set_sensitive(mimeview->popupfactory,
					   "/Open", FALSE);
		else
			menu_set_sensitive(mimeview->popupfactory,
					   "/Open", TRUE);

		menu_set_sensitive(mimeview->popupfactory,
				   "/Save all...", mimeview->has_attach_file);

		if (partinfo && (partinfo->mime_type == MIME_TEXT ||
				 partinfo->mime_type == MIME_TEXT_HTML ||
				 partinfo->mime_type == MIME_MESSAGE_RFC822))
			menu_set_sensitive(mimeview->popupfactory,
					   "/Print...", TRUE);
		else
			menu_set_sensitive(mimeview->popupfactory,
					   "/Print...", FALSE);

		if (partinfo && partinfo->mime_type == MIME_MESSAGE_RFC822) {
			gtk_widget_show(mimeview->reply_separator);
			gtk_widget_show(mimeview->reply_menuitem);
		} else {
			gtk_widget_hide(mimeview->reply_separator);
			gtk_widget_hide(mimeview->reply_menuitem);
		}
#if USE_GPGME
		menu_set_sensitive(mimeview->popupfactory,
				   "/Check signature",
				   mimeview_is_signed(mimeview));
#endif

		gtk_menu_popup(GTK_MENU(mimeview->popupmenu),
			       NULL, NULL, NULL, NULL,
			       event->button, event->time);
		return TRUE;
	}

	return FALSE;
}