Ejemplo n.º 1
0
static void
on_activate(InfGtkBrowserView* view,
            GtkTreeIter* iter,
            gpointer user_data)
{
  InfcBrowser* browser;
  InfcBrowserIter* browser_iter;

  gtk_tree_model_get(
    GTK_TREE_MODEL(inf_gtk_browser_view_get_model(view)),
    iter,
    INF_GTK_BROWSER_MODEL_COL_BROWSER, &browser,
    INF_GTK_BROWSER_MODEL_COL_NODE, &browser_iter,
    -1
  );

  /* Subscribe, if possible and not already */
  if(!infc_browser_iter_get_session(browser, browser_iter) &&
     !infc_browser_iter_get_subscribe_request(browser, browser_iter) &&
     infc_browser_iter_get_plugin(browser, browser_iter) != NULL)
  {
    infc_browser_iter_subscribe_session(browser, browser_iter);
  }

  infc_browser_iter_free(browser_iter);
  g_object_unref(browser);
}
/* Copied from gobby: code/core/browser.cpp */
static gint
compare_func (GtkTreeModel *model,
              GtkTreeIter  *first,
              GtkTreeIter  *second,
              gpointer      user_data)
{
	gint result;
	InfcBrowser *br_one;
	InfcBrowser *br_two;
	InfcBrowserIter *bri_one;
	InfcBrowserIter *bri_two;
	GtkTreeIter parent;

	result = 0;

	if (gtk_tree_model_iter_parent (model, &parent, first))
	{
		g_assert (gtk_tree_model_iter_parent (model, &parent, second));

		gtk_tree_model_get (model,
		                   first,
		                   INF_GTK_BROWSER_MODEL_COL_BROWSER,
		                   &br_one,
		                   INF_GTK_BROWSER_MODEL_COL_NODE,
		                   &bri_one,
		                   -1);

		gtk_tree_model_get (model,
		                    second,
		                    INF_GTK_BROWSER_MODEL_COL_BROWSER,
		                    &br_two,
		                    INF_GTK_BROWSER_MODEL_COL_NODE,
		                    &bri_two,
		                    -1);

		if (infc_browser_iter_is_subdirectory (br_one, bri_one) &&
		   !infc_browser_iter_is_subdirectory (br_two, bri_two))
		{
			result = -1;
		}
		else if (!infc_browser_iter_is_subdirectory(br_one, bri_one) &&
		          infc_browser_iter_is_subdirectory(br_two, bri_two))
		{
			result = 1;
		}

		g_object_unref (br_one);
		g_object_unref (br_two);

		infc_browser_iter_free (bri_one);
		infc_browser_iter_free (bri_two);
	}

	if (!result)
	{
		gchar* name_one;
		gchar* name_two;

		gtk_tree_model_get (model,
		                    first,
		                    INF_GTK_BROWSER_MODEL_COL_NAME,
		                    &name_one,
		                    -1);

		gtk_tree_model_get (model,
		                    second,
		                    INF_GTK_BROWSER_MODEL_COL_NAME,
		                    &name_two,
		                    -1);

		gchar* one = g_utf8_casefold (name_one, -1);
		gchar* two = g_utf8_casefold (name_two, -1);

		result = g_utf8_collate (one, two);

		g_free (name_one);
		g_free (name_two);
		g_free (one);
		g_free (two);
	}

	return result;
}
static void
on_browser_activate (InfGtkBrowserView              *view,
                     GtkTreeIter                    *iter,
                     GeditCollaborationWindowHelper *helper)
{
	InfcBrowser *browser;
	InfcBrowserIter *browser_iter;
	InfDiscovery *discovery;
	GeditCollaborationUser *user;
	GtkTreeIter selected;

	gtk_tree_model_sort_convert_iter_to_child_iter (
		GTK_TREE_MODEL_SORT (inf_gtk_browser_view_get_model (view)),
		&selected,
		iter
	);

	gtk_tree_model_get (GTK_TREE_MODEL (helper->priv->browser_store),
	                    &selected,
	                    INF_GTK_BROWSER_MODEL_COL_BROWSER,
	                    &browser,
	                    INF_GTK_BROWSER_MODEL_COL_DISCOVERY,
	                    &discovery,
	                    -1);

	if (browser == NULL)
	{
		if (discovery)
		{
			g_object_unref (discovery);
		}

		return;
	}

	gtk_tree_model_get (GTK_TREE_MODEL (helper->priv->browser_store),
	                    &selected,
	                    INF_GTK_BROWSER_MODEL_COL_NODE,
	                    &browser_iter,
	                    -1);

	if (browser_iter == NULL ||
	    infc_browser_iter_is_subdirectory (browser, browser_iter))
	{
		g_object_unref (browser);

		if (browser_iter)
		{
			infc_browser_iter_free (browser_iter);
		}

		if (discovery)
		{
			g_object_unref (discovery);
		}

		return;
	}

	if (discovery)
	{
		user = gedit_collaboration_user_get_default ();
	}
	else
	{
		GeditCollaborationBookmark *bookmark;

		bookmark = g_object_get_data (G_OBJECT (infc_browser_get_connection (browser)),
		                              BOOKMARK_DATA_KEY);

		user = gedit_collaboration_bookmark_get_user (bookmark);
	}

	gedit_collaboration_manager_subscribe (helper->priv->manager,
	                                       user,
	                                       browser,
	                                       browser_iter);

	if (discovery)
	{
		g_object_unref (discovery);
	}

	if (browser_iter)
	{
		infc_browser_iter_free (browser_iter);
	}
}
static void
item_new_dialog (GeditCollaborationWindowHelper *helper,
                 gboolean                        newfile)
{
	GtkWidget *dialog;
	ItemNew *item;
	GtkTreeIter iter;
	GtkTreeIter selected;
	InfcBrowser *browser;
	InfcBrowserIter *node;
	GtkWidget *label;
	GtkWidget *entry;
	GtkWidget *hbox;

	if (!inf_gtk_browser_view_get_selected (INF_GTK_BROWSER_VIEW (helper->priv->browser_view),
	                                        &selected))
	{
		return;
	}

	gtk_tree_model_sort_convert_iter_to_child_iter (
		GTK_TREE_MODEL_SORT (
			gtk_tree_view_get_model (
				GTK_TREE_VIEW (helper->priv->browser_view)
			)
		),
		&iter,
		&selected
	);

	dialog = gtk_dialog_new_with_buttons (newfile ? _("New File") : _("New Folder"),
	                                      GTK_WINDOW (helper->priv->window),
	                                      GTK_DIALOG_DESTROY_WITH_PARENT,
	                                      GTK_STOCK_CANCEL,
	                                      GTK_RESPONSE_CANCEL,
	                                      GTK_STOCK_OK,
	                                      GTK_RESPONSE_OK,
	                                      NULL);

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	gtk_widget_show (hbox);

	label = gtk_label_new_with_mnemonic (newfile ? _("File _name:") : _("Folder _name:"));
	gtk_widget_show (label);

	entry = gtk_entry_new ();
	gtk_widget_show (entry);
	gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);

	gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);

	gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);

	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
	                    hbox,
	                    FALSE,
	                    FALSE,
	                    0);

	gtk_tree_model_get (GTK_TREE_MODEL (helper->priv->browser_store),
	                    &iter,
	                    INF_GTK_BROWSER_MODEL_COL_BROWSER,
	                    &browser,
	                    INF_GTK_BROWSER_MODEL_COL_NODE,
	                    &node,
	                    -1);

	item = g_slice_new (ItemNew);
	item->helper = helper;
	item->iter = *node;
	item->browser = browser;
	item->newfile = newfile;
	item->entry = GTK_ENTRY (entry);

	infc_browser_iter_free (node);

	g_signal_connect (dialog,
	                  "response",
	                  G_CALLBACK (on_item_new_response),
	                  item);

	gtk_widget_show (dialog);
}
void
on_action_item_delete (GtkAction                      *action,
                       GeditCollaborationWindowHelper *helper)
{
	GtkTreeIter iter;
	GtkTreeIter selected;
	InfcBrowser *browser;
	InfcBrowserIter *browser_iter;
	InfcBrowserIter parent;

	if (!inf_gtk_browser_view_get_selected (INF_GTK_BROWSER_VIEW (helper->priv->browser_view),
	                                        &selected))
	{
		return;
	}

	gtk_tree_model_sort_convert_iter_to_child_iter (
		GTK_TREE_MODEL_SORT (
			gtk_tree_view_get_model (
				GTK_TREE_VIEW (helper->priv->browser_view)
			)
		),
		&iter,
		&selected
	);

	gtk_tree_model_get (GTK_TREE_MODEL (helper->priv->browser_store),
	                    &iter,
	                    INF_GTK_BROWSER_MODEL_COL_BROWSER,
	                    &browser,
	                    INF_GTK_BROWSER_MODEL_COL_NODE,
	                    &browser_iter,
	                    -1);

	parent = *browser_iter;

	if (!infc_browser_iter_get_parent (browser, &parent))
	{
		/* Toplevel bookmark */
		InfXmlConnection *connection = infc_browser_get_connection (browser);
		GeditCollaborationBookmarks *bookmarks;
		GeditCollaborationBookmark *bookmark =
			g_object_get_data (G_OBJECT (connection),
			                   BOOKMARK_DATA_KEY);

		/* Close connection first */
		if (infc_browser_get_status (browser) != INFC_BROWSER_DISCONNECTED)
		{
			inf_xml_connection_close (connection);
		}

		inf_gtk_browser_store_remove_connection (helper->priv->browser_store,
		                                         connection);

		bookmarks = gedit_collaboration_bookmarks_get_default ();
		gedit_collaboration_bookmarks_remove (bookmarks, bookmark);
	}
	else
	{
		/* Remove the iter itself */
		infc_browser_remove_node (browser, browser_iter);
	}

	g_object_unref (browser);

	if (browser_iter)
	{
		infc_browser_iter_free (browser_iter);
	}
}