示例#1
0
static VALUE
rg_convert_path_to_child_path(VALUE self, VALUE filter_path)
{
    return GTKTREEPATH2RVAL(gtk_tree_model_filter_convert_path_to_child_path(
                             _SELF(self),
                             RVAL2GTKTREEPATH(filter_path)));
}
示例#2
0
/* 
   If m is not a base TreeModel type (ie, is a filter or sorter) then 
   convert OP to a TreePath for the base and return it.
   The return value must be freed by the caller.
*/
static GtkTreePath *
get_base_tree_path (GtkTreeModel *m, GtkTreePath *op)
{
  GtkTreePath *p = gtk_tree_path_copy (op);
  while ( ! PSPPIRE_IS_DICT (m))
    {
      GtkTreePath *oldp = p;
      
      if (GTK_IS_TREE_MODEL_FILTER (m))
	{
	  p = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (m), oldp);
	  m = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (m));
	}
      else if (GTK_IS_TREE_MODEL_SORT (m))
	{
	  p = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT (m), oldp);
	  m = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (m));
	}
      else
	{
	  g_error ("Unexpected model type: %s", G_OBJECT_TYPE_NAME (m));
	}
      
      gtk_tree_path_free (oldp);
    }

  return p;
}
示例#3
0
文件: tasks_items.c 项目: rosedu/osmo
void
tasks_remove_dialog_show (GtkWidget *list, GtkListStore *list_store) {

GtkWidget *info_dialog, *label;
gint response;
GtkTreePath *sort_path, *filter_path, *path;
GtkTreeIter iter;

    gtk_tree_view_get_cursor (GTK_TREE_VIEW (list), &sort_path, NULL);

    if (sort_path != NULL) {

        filter_path = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT(tasks_sort), sort_path);

        if (filter_path != NULL) {

            path = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER(tasks_filter), filter_path);

            if (path != NULL) {

                sprintf(tmpbuf, "%s\n\n%s", _("Selected task will be removed."), _("Are you sure ?"));

                if (config.default_stock_icons) {
                    info_dialog = gtk_message_dialog_new (GTK_WINDOW(main_window), 
                                                          GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
                                                          GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, tmpbuf);
                    gtk_window_set_title(GTK_WINDOW(info_dialog), _("Remove task"));
                } else {
                    info_dialog = gtk_dialog_new_with_buttons (_("Remove task"), GTK_WINDOW(main_window), 
                                                          GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
                                                          OSMO_STOCK_BUTTON_NO, GTK_RESPONSE_NO, 
                                                          OSMO_STOCK_BUTTON_YES, GTK_RESPONSE_YES, NULL);
                    gtk_window_set_default_size (GTK_WINDOW(info_dialog), 360, 150);
                    label = gtk_label_new (tmpbuf);
                    gtk_widget_show (label);
                    gtk_box_pack_start (GTK_BOX (GTK_DIALOG(info_dialog)->vbox), label, TRUE, TRUE, 0);
                }

                gtk_widget_show (info_dialog);
                response = gtk_dialog_run(GTK_DIALOG(info_dialog));
                gtk_widget_destroy(info_dialog);

                if (response == GTK_RESPONSE_YES) {   
                    gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, path);
                    gtk_list_store_remove(list_store, &iter);
                    gtk_tree_path_free(path);
                    tasks_select_first_position_in_list();
                    update_n_items();
                    g_signal_emit_by_name(G_OBJECT(calendar), "day-selected");
                }
            }

            gtk_tree_path_free(filter_path);
        }

        gtk_tree_path_free(sort_path);
    }
}
示例#4
0
void on_dir_tree_view_row_collapsed( GtkTreeView *treeview,
                                     GtkTreeIter *iter,
                                     GtkTreePath *path,
                                     gpointer user_data )
{
    GtkTreeIter real_it;
    GtkTreePath* real_path;
    GtkTreeModel* filter = gtk_tree_view_get_model( treeview );
    PtkDirTree* tree = PTK_DIR_TREE( user_data );
    gtk_tree_model_filter_convert_iter_to_child_iter(
        GTK_TREE_MODEL_FILTER( filter ), &real_it, iter );
    real_path = gtk_tree_model_filter_convert_path_to_child_path(
                    GTK_TREE_MODEL_FILTER( filter ), path );
    ptk_dir_tree_collapse_row( tree, &real_it, real_path );
    gtk_tree_path_free( real_path );
}
示例#5
0
/* Returns true iff the variable selected by SOURCE is numeric */
gboolean
numeric_only (GtkWidget *source, GtkWidget *dest)
{
  gboolean retval = TRUE;

  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));

  PsppireDict *dict;
  GtkTreeSelection *selection;
  GList *list, *l;

  while (GTK_IS_TREE_MODEL_FILTER (model))
    {
      model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
    }

  dict = PSPPIRE_DICT (model);

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));

  list = gtk_tree_selection_get_selected_rows (selection, &model);

  /* Iterate through the selection of the source treeview */
  for (l = list; l ; l = l->next)
    {
      GtkTreePath *path = l->data;
      GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path
	(GTK_TREE_MODEL_FILTER (model), path);

      gint *idx = gtk_tree_path_get_indices (fpath);

      const struct variable *v = psppire_dict_get_variable (dict, idx[0]);

      gtk_tree_path_free (fpath);

      if ( var_is_alpha (v))
	{
	  retval = FALSE;
	  break;
	}
    }

  g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
  g_list_free (list);

  return retval;
}
示例#6
0
/*
 * Retrieve the selected owner from an owner tree view.  The
 * owner tree must be in single selection mode.
 */
GncOwner *
gnc_tree_view_owner_get_owner_from_path (GncTreeViewOwner *view,
        GtkTreePath *s_path)
{
    GtkTreeModel *model, *f_model, *s_model;
    GtkTreePath *path, *f_path;
    GtkTreeIter iter;
    GncOwner *owner;

    ENTER("view %p", view);
    g_return_val_if_fail (GNC_IS_TREE_VIEW_OWNER (view), NULL);
    g_return_val_if_fail (s_path != NULL, NULL);

    s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
    f_path = gtk_tree_model_sort_convert_path_to_child_path (
                 GTK_TREE_MODEL_SORT (s_model), s_path);
    if (!f_path)
    {
        LEAVE("no filter path");
        return NULL;
    }

    f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
    path = gtk_tree_model_filter_convert_path_to_child_path (
               GTK_TREE_MODEL_FILTER (f_model), f_path);
    gtk_tree_path_free(f_path);
    if (!path)
    {
        LEAVE("no path");
        return NULL;
    }

    model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
    if (!gtk_tree_model_get_iter (model, &iter, path))
    {
        LEAVE("no iter");
        return NULL;
    }

    owner = iter.user_data;
    gtk_tree_path_free(path);
    LEAVE("owner %p (%s)", owner, gncOwnerGetName (owner));
    return owner;
}
示例#7
0
文件: tasks_items.c 项目: rosedu/osmo
void
tasks_remove_dialog_show (GtkWidget *list, GtkListStore *list_store, GUI *appGUI) {

gint response;
GtkTreePath *sort_path, *filter_path, *path;
GtkTreeIter iter;
gchar tmpbuf[BUFFER_SIZE];

    gtk_tree_view_get_cursor (GTK_TREE_VIEW (list), &sort_path, NULL);

    if (sort_path != NULL) {

        filter_path = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT(appGUI->tsk->tasks_sort), sort_path);

        if (filter_path != NULL) {

            path = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER(appGUI->tsk->tasks_filter), filter_path);

            if (path != NULL) {

                sprintf (tmpbuf, "%s\n\n%s", _("Selected task will be removed."), _("Are you sure?"));

                response = gui_create_dialog(GTK_MESSAGE_QUESTION, tmpbuf, GTK_WINDOW(appGUI->main_window));

                if (response == GTK_RESPONSE_YES) {   
                    gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, path);
                    gtk_list_store_remove(list_store, &iter);
                    gtk_tree_path_free(path);
                    tasks_select_first_position_in_list(appGUI);
                    update_n_items(appGUI);
                    g_signal_emit_by_name(G_OBJECT(appGUI->cal->calendar), "day-selected");
                    gui_systray_tooltip_update(appGUI);
                }
            }

            gtk_tree_path_free(filter_path);
        }

        gtk_tree_path_free(sort_path);
    }
}
示例#8
0
文件: tasks.c 项目: rosedu/osmo
void
done_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data) {

/*GtkTreeModel *model = (GtkTreeModel *)data;*/
GtkTreePath *sort_path, *filter_path, *path;
GtkTreeIter  iter;
gboolean done_status;
GtkTreeModel *model;

    GUI *appGUI = (GUI *)data;
    model = GTK_TREE_MODEL(appGUI->tsk->tasks_list_store);

    sort_path = gtk_tree_path_new_from_string (path_str);

    if (sort_path != NULL) {

        filter_path = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT(appGUI->tsk->tasks_sort), sort_path);

        if (filter_path != NULL) {

            path = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER(appGUI->tsk->tasks_filter), filter_path);

            if (path != NULL) {
                gtk_tree_model_get_iter (model, &iter, path);   /* get toggled iter */
                gtk_tree_model_get (model, &iter, COLUMN_DONE, &done_status, -1);
                gtk_list_store_set (GTK_LIST_STORE(model), &iter, COLUMN_DONE, !done_status, -1);

                if (done_status == TRUE && config.delete_completed) {
                    gtk_list_store_remove(GTK_LIST_STORE (model), &iter);
                }

                gtk_tree_path_free (path);
            }
            gtk_tree_path_free (filter_path);
        }
        gtk_tree_path_free (sort_path);
    }

    apply_date_colors(appGUI);
}
示例#9
0
文件: tasks_items.c 项目: rosedu/osmo
void
tasks_item_entered_cb (GtkWidget *widget, gpointer data) {

GtkTextBuffer *text_buffer;
GtkTextIter iter_a, iter_b;
GtkTreePath *sort_path, *filter_path, *path;
GtkTreeIter iter;
guint32 fstartdate;

    GUI *appGUI = (GUI *)data;

    if (appGUI->tsk->tasks_edit_state == TRUE) {

        gtk_tree_view_get_cursor (GTK_TREE_VIEW (appGUI->tsk->tasks_list), &sort_path, NULL);

        if (sort_path != NULL) {

            filter_path = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT(appGUI->tsk->tasks_sort), sort_path);

            if (filter_path != NULL) {

                path = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER(appGUI->tsk->tasks_filter), filter_path);

                if (path != NULL) {
                    gtk_tree_model_get_iter(GTK_TREE_MODEL(appGUI->tsk->tasks_list_store), &iter, path);
                    gtk_tree_model_get (GTK_TREE_MODEL(appGUI->tsk->tasks_list_store), &iter, 
                               COLUMN_START_DATE_JULIAN, &fstartdate, -1);
                    gtk_list_store_remove(appGUI->tsk->tasks_list_store, &iter);
                    gtk_tree_path_free(path);
                }

                gtk_tree_path_free(filter_path);
            }

            gtk_tree_path_free(sort_path);
        }
    }

    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(appGUI->tsk->desc_textview));
    gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(text_buffer), &iter_a, 0);
    gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(text_buffer), &iter_b, -1);

    if(appGUI->tsk->tasks_edit_state == TRUE) {
        add_item_to_list(FALSE,
                         appGUI->tsk->tasks_due_julian_day,
                         fstartdate,
                         gtk_combo_box_get_active_text(GTK_COMBO_BOX(appGUI->tsk->priority_combobox)),
                         gtk_combo_box_get_active_text(GTK_COMBO_BOX(appGUI->tsk->category_combobox)),
                         (gchar *) gtk_entry_get_text(GTK_ENTRY(appGUI->tsk->summary_entry)),
                         gtk_text_buffer_get_text(GTK_TEXT_BUFFER(text_buffer), &iter_a, &iter_b, TRUE), appGUI);

    } else {
        add_item_to_list(FALSE, 
                         appGUI->tsk->tasks_due_julian_day,
                         get_julian_for_today(),
                         gtk_combo_box_get_active_text(GTK_COMBO_BOX(appGUI->tsk->priority_combobox)),
                         gtk_combo_box_get_active_text(GTK_COMBO_BOX(appGUI->tsk->category_combobox)),
                         (gchar *) gtk_entry_get_text(GTK_ENTRY(appGUI->tsk->summary_entry)),
                         gtk_text_buffer_get_text(GTK_TEXT_BUFFER(text_buffer), &iter_a, &iter_b, TRUE), appGUI);
    }

    gtk_widget_destroy(appGUI->tsk->tasks_add_window);
    update_n_items(appGUI);
    tasks_select_first_position_in_list(appGUI);
    g_signal_emit_by_name(G_OBJECT(appGUI->cal->calendar), "day-selected");
}
static void
on_popupmenu_activated_recordingdelete (GtkMenuItem *menuitem, gpointer user_data)
{
	FreetuxTVApp *app = (FreetuxTVApp *)user_data;

	GError* error = NULL;

	GtkWidget* pParent;
	GtkWidget* treeview;
	GtkTreeModel* model_filter;
	GtkTreeSelection *selection;
	GList *list;
	GList* iterator = NULL;
	GtkTreePath *path;
	GtkTreePath *real_path;
	
	DBSync dbsync;
	dbsync_open_db (&dbsync, &error);

	gboolean bDeleteFile = FALSE;

	if(error == NULL){
		treeview =  (GtkWidget *) gtk_builder_get_object (app->gui,
		    "windowmain_treeviewfinishedrecordings");
		model_filter = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
		
		// Get the selection
		selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
		list = gtk_tree_selection_get_selected_rows (selection, &model_filter);

		if(list == NULL){
			treeview = (GtkWidget *) gtk_builder_get_object (app->gui,
				"windowmain_treeviewrecordings");
			model_filter = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
		
			// Get the selection
			selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
			list = gtk_tree_selection_get_selected_rows (selection, &model_filter);
		}

		if(list != NULL){
			GtkWidget* dialog;
			pParent = (GtkWidget *) gtk_builder_get_object (app->gui,
				"windowmain");
			dialog = gtk_message_dialog_new (GTK_WINDOW(pParent),
			    GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
			    _("Do you want to move the related file on the hard disk to the trash?"));
			int res = gtk_dialog_run(GTK_DIALOG(dialog));
			if(res == GTK_RESPONSE_YES){
				bDeleteFile = TRUE;
			}
			gtk_widget_destroy (dialog);
			dialog = NULL;
		}
		
		iterator = g_list_last (list);

		while(iterator != NULL && error == NULL){			

			// Get the real path
			path = (GtkTreePath*)iterator->data;
			real_path = gtk_tree_model_filter_convert_path_to_child_path(GTK_TREE_MODEL_FILTER(model_filter), path);
			
			// Delete the recordings corresponding to the path
			recordings_list_delete_recording(app, real_path, bDeleteFile, &dbsync, &error);

			iterator = g_list_previous(iterator);
		}
	}
	
	dbsync_close_db(&dbsync);

	if(error == NULL){
		windowmain_update_statusbar_infos (app);
	}
	
	if(error != NULL){
		windowmain_show_gerror (app, error);
		g_error_free (error);
	}
}
static gboolean
on_button_press_event_recordings_list (GtkWidget *treeview, GdkEventButton *event, gpointer user_data)
{

	FreetuxTVApp *app = (FreetuxTVApp *) user_data;

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

		GtkTreeSelection *selection;
		GtkTreeModel* model_filter;
		GList *list;
		gint nbRecordingsTab[TYPERECORDING_COUNT+1] = {0, 0, 0};

		GtkTreePath *path;
		GtkTreePath *path_selected;

		model_filter = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
		
		// Get the selection
		selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
		
		// Select the path where user has clicked if not selected
		if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview),
						  (gint) event->x, (gint) event->y,
						  &path_selected, NULL, NULL, NULL)){
			if(!gtk_tree_selection_path_is_selected (selection, path_selected)){
				gtk_tree_selection_unselect_all (selection);
				gtk_tree_selection_select_path(selection, path_selected);
			}
			gtk_tree_path_free(path_selected);
			path_selected = NULL;
		}

		// Get the final list of selected item
		list = gtk_tree_selection_get_selected_rows (selection, &model_filter);
		
		//nbTotalGroupsVisible = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(model_filter), NULL);

		// Count number of elements selected by category
		GList* iterator = NULL;
		iterator = g_list_first (list);
		while(iterator != NULL){
			GtkTreePath *real_path;
			GtkTreeIter iter;

			// Get the real path
			path = (GtkTreePath*)iterator->data;
			real_path = gtk_tree_model_filter_convert_path_to_child_path(GTK_TREE_MODEL_FILTER(model_filter), path);
			
			// Look the type of the data in the path
			FreetuxTVRecordingInfos* pRecordingInfo;
			gtk_tree_model_get_iter (GTK_TREE_MODEL(app->pRecordingList), &iter, real_path);
			gtk_tree_model_get(GTK_TREE_MODEL(app->pRecordingList), &iter, RECORDING_COLUMN, &pRecordingInfo, -1);
			if(pRecordingInfo != NULL){
				switch(pRecordingInfo->status)
				{
					case FREETUXTV_RECORDING_STATUS_PROCESSING :
					case FREETUXTV_RECORDING_STATUS_WAITING :
						nbRecordingsTab[TYPERECORDING_INPROGRESS]++;
						break;
					default:
						nbRecordingsTab[TYPERECORDING_TERMINATED]++;
						break;
				}
				nbRecordingsTab[TYPERECORDING_COUNT]++;
			}

			// Iterate next path
			iterator = g_list_next(iterator);
		}

		GtkWidget *pMenu = NULL;
		GtkWidget *pMenuItem;

		if(nbRecordingsTab[TYPERECORDING_COUNT] > 0){
			pMenu = gtk_menu_new();
			g_signal_connect(G_OBJECT(pMenu), "selection-done",
			    G_CALLBACK(on_popupmenu_selectiondone), app);

			// Delete channels from favourites group
			pMenuItem = gtk_image_menu_item_new_from_stock ("gtk-delete", NULL);
#if GTK_API_VERSION == 3
			gtk_menu_shell_append (GTK_MENU_SHELL (pMenu), pMenuItem);
#else
			gtk_menu_append (GTK_MENU (pMenu), pMenuItem);
#endif
			g_signal_connect(G_OBJECT(pMenuItem), "activate",
			    G_CALLBACK(on_popupmenu_activated_recordingdelete), app);
			gtk_widget_show (pMenuItem);
		}			 

		if(pMenu){
			gtk_widget_show(pMenu);
			
			gtk_menu_popup(GTK_MENU(pMenu), NULL, NULL, NULL, NULL,
				       (event != NULL) ? event->button : 0,
				       gdk_event_get_time((GdkEvent*)event));
		}

		return TRUE;
	}

	return FALSE;
}
示例#12
0
gint
birthdays_list_dbclick_cb (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
{
GtkTreeIter iter;
GtkTreeModel *model, *contacts_model;
GtkTreePath *sort_path, *filter_path, *path;
gint id, id_c;

    GUI *appGUI = (GUI *) user_data;
	contacts_model = GTK_TREE_MODEL (appGUI->cnt->contacts_list_store);

    if (((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) == FALSE)
	    return FALSE;

	if (gtk_tree_selection_get_selected (appGUI->cnt->birthdays_list_selection, &model, &iter)) {

		if (strlen (gtk_entry_get_text (GTK_ENTRY (appGUI->cnt->contacts_find_entry)))) {
			gtk_entry_set_text (GTK_ENTRY (appGUI->cnt->contacts_find_entry), "");
			gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (appGUI->cnt->contacts_filter));
		}

		gtk_tree_model_get (model, &iter, B_COLUMN_ID, &id, -1);
		gtk_widget_destroy (appGUI->cnt->birthdays_window);

		contacts_selection_activate (FALSE, appGUI);

		if (gtk_tree_model_get_iter_first (contacts_model, &iter) == TRUE) {
			sort_path = gtk_tree_model_get_path (contacts_model, &iter);

			while (sort_path != NULL) {
				gtk_tree_view_set_cursor (GTK_TREE_VIEW (appGUI->cnt->contacts_list), sort_path, NULL, FALSE);
				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 (contacts_model, &iter, path);
						gtk_tree_model_get (contacts_model, &iter, COLUMN_ID, &id_c, -1);

						if (id == id_c) {
							contacts_selection_activate (TRUE, appGUI);
							gtk_tree_view_set_cursor (GTK_TREE_VIEW (appGUI->cnt->contacts_list), sort_path, NULL, FALSE);
							show_contacts_desc_panel (TRUE, appGUI);
							gtk_tree_path_free (path);
							gtk_tree_path_free (filter_path);
							g_signal_emit_by_name (G_OBJECT (appGUI->cnt->contacts_list_selection), "changed");
							break;
						}

						gtk_tree_path_free (path);
					}

					gtk_tree_path_free (filter_path);
				}

				gtk_tree_path_next (sort_path);
				if (gtk_tree_model_get_iter (contacts_model, &iter, sort_path) == FALSE) break;
			}

			gtk_tree_path_free (sort_path);
		}

	}

	return TRUE;
}
示例#13
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;
}
示例#14
0
文件: tasks.c 项目: rosedu/osmo
void
fill_fields (GtkWidget *due_date_entry, GtkWidget *summary_entry, GtkWidget *desc_entry, GUI *appGUI) {

GtkTreeIter iter;
GtkTextIter titer;
GtkTreePath *sort_path, *filter_path, *path;
gchar *fduedate, *fpriority, *fcategory, *fsummary, *fdesc;
GtkTextBuffer *text_buffer;


    gtk_tree_view_get_cursor (GTK_TREE_VIEW (appGUI->tsk->tasks_list), &sort_path, NULL);

    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(desc_entry));
    gui_clear_text_buffer (text_buffer, &titer);

    if (sort_path != NULL) {

        filter_path = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT(appGUI->tsk->tasks_sort), sort_path);

        if (filter_path != NULL) {

            path = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER(appGUI->tsk->tasks_filter), filter_path);

            if (path != NULL) {

                gtk_tree_model_get_iter(GTK_TREE_MODEL(appGUI->tsk->tasks_list_store), &iter, path);

                gtk_tree_model_get (GTK_TREE_MODEL(appGUI->tsk->tasks_list_store), &iter, 
                           COLUMN_DUE_DATE, &fduedate, 
                           COLUMN_DUE_DATE_JULIAN, &appGUI->tsk->tasks_due_julian_day, 
                           COLUMN_PRIORITY, &fpriority,
                           COLUMN_CATEGORY, &fcategory,
                           COLUMN_SUMMARY, &fsummary, 
                           COLUMN_DESCRIPTION, &fdesc, -1);

                gtk_entry_set_text(GTK_ENTRY(due_date_entry), fduedate);
                g_free(fduedate);
                gtk_entry_set_text(GTK_ENTRY(summary_entry), fsummary);
                g_free(fsummary);

                gtk_combo_box_set_active(GTK_COMBO_BOX(appGUI->tsk->category_combobox), 
                                         gui_list_store_get_text_index (appGUI->opt->tasks_category_store, fcategory));
                g_free(fcategory);
                gtk_combo_box_set_active(GTK_COMBO_BOX(appGUI->tsk->priority_combobox), 
                                         get_priority_index (fpriority));
                g_free(fpriority);

                gtk_text_buffer_get_iter_at_offset(GTK_TEXT_BUFFER(text_buffer), &titer, 0);

                if (fdesc != NULL) {
                    gtk_text_buffer_insert(text_buffer, &titer, fdesc, -1);
                    gtk_text_view_set_buffer(GTK_TEXT_VIEW(desc_entry), text_buffer);
                    g_free(fdesc);
                }

                gtk_tree_path_free(path);

            }

            gtk_tree_path_free(filter_path);
        }

        gtk_tree_path_free(sort_path);
    }
}
示例#15
0
文件: pdm-dialog.c 项目: GNOME/galeon
static GList *
get_remove_list(PdmActionInfo *action)
{
	GList *l, *model_iters, *sorter_paths, *remove_list;
	GtkTreeModel *model, *sorter, *filter;
	GtkTreeSelection *selection;

	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(action->treeview));
	sorter_paths = gtk_tree_selection_get_selected_rows(selection, &sorter);

	/* We have our list of selected paths, update selection now to avoid
	 * multiple signals when we start removing things.  If only single row
	 * was selected, attempt to select the next one below.  No harm done if
	 * it fails (we're not trying to select the row above because Evolution
	 * isn't either.)
	 */
	gtk_tree_selection_unselect_all(selection);
	if (sorter_paths != NULL && sorter_paths->next == NULL)
	{
		GtkTreePath *select_path;

		select_path = gtk_tree_path_copy(sorter_paths->data);
		gtk_tree_path_next(select_path);
		gtk_tree_selection_select_path(selection, select_path);
		gtk_tree_path_free(select_path);
	}

	/* Paths are somewhat fragile, removing a row will invalidate all the
	 * following paths (they will be referring to the row below the one
	 * they used to) and you'll end up removing random items.  Convert
	 * paths to TreeIters which persist (at least with ListStore they do.)
	 */
	filter = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(sorter));
	model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(filter));

	model_iters = NULL;
	for (l = sorter_paths; l != NULL; l = l->next)
	{
		GtkTreePath *sorter_path = l->data;
		GtkTreePath *filter_path, *model_path;
		GtkTreeIter  iter;

		filter_path = gtk_tree_model_sort_convert_path_to_child_path
			(GTK_TREE_MODEL_SORT(sorter), sorter_path);
		model_path = gtk_tree_model_filter_convert_path_to_child_path
			(GTK_TREE_MODEL_FILTER(filter), filter_path);

		if (gtk_tree_model_get_iter(model, &iter, model_path))
		{
			model_iters = g_list_prepend(model_iters, gtk_tree_iter_copy(&iter));
		}

		gtk_tree_path_free(model_path);
		gtk_tree_path_free(filter_path);
		gtk_tree_path_free(sorter_path);
	}
	g_list_free(sorter_paths);

	/* It's now safe to turn off your computer... I mean, remove the rows. */
	remove_list = NULL;
	for (l = model_iters; l != NULL; l = l->next)
	{
		GtkTreeIter *iter = l->data;
		GList       *link;
		gpointer     data;

		gtk_tree_model_get(model, iter, action->data_col, &data, -1);

		link = g_list_find(action->list, data);
		action->list = g_list_remove_link(action->list, link);
		remove_list = g_list_concat(link, remove_list);

		gtk_list_store_remove(GTK_LIST_STORE(model), iter);
		gtk_tree_iter_free(iter);
	}
	g_list_free(model_iters);

	return remove_list;
}
示例#16
0
/* Returns FALSE if the variables represented by the union of the rows
   currently selected by SOURCE widget, and contents of the DEST
   widget, are of different types.

   In other words, this function when passed as the argument to
   psppire_selector_set_allow, ensures that the selector selects only
   string  variables, or only numeric variables, not a mixture.
*/
gboolean
homogeneous_types (GtkWidget *source, GtkWidget *dest)
{
  gboolean ok;
  GtkTreeIter iter;
  gboolean retval = TRUE;

  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source));

  PsppireDict *dict;
  GtkTreeSelection *selection;
  enum val_type type = -1;
  GList *list, *l;

  while (GTK_IS_TREE_MODEL_FILTER (model))
    {
      model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
    }

  dict = PSPPIRE_DICT (model);

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source));

  list = gtk_tree_selection_get_selected_rows (selection, &model);

  /* Iterate through the selection of the source treeview */
  for (l = list; l ; l = l->next)
    {
      GtkTreePath *path = l->data;

      GtkTreePath *fpath =
	gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path);

      gint *idx = gtk_tree_path_get_indices (fpath);

      const struct variable *v = psppire_dict_get_variable (dict, idx[0]);

      gtk_tree_path_free (fpath);

      if ( type != -1 )
	{
	  if ( var_get_type (v) != type )
	    {
	      retval = FALSE;
	      break;
	    }
	}

      type = var_get_type (v);
    }

  g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
  g_list_free (list);

  if ( retval == FALSE )
    return FALSE;

  /* now deal with the dest widget */
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));

  for (ok = gtk_tree_model_get_iter_first (model, &iter);
       ok;
       ok = gtk_tree_model_iter_next (model, &iter))
    {
      const struct variable *v;
      gtk_tree_model_get (model, &iter, 0, &v, -1);

      if ( type != -1 )
	{
	  if ( var_get_type (v) != type )
	    {
	      retval = FALSE;
	      break;
	    }
	}

      type = var_get_type (v);
    }

  return retval;
}