Factor out katze_xbel_folder_from_data_dirs and _to_data

This commit is contained in:
Christian Dywan 2008-09-04 00:35:15 +02:00
parent 065cfd0816
commit 1d047c4ab5
5 changed files with 53 additions and 101 deletions

View file

@ -764,32 +764,6 @@ katze_xbel_folder_from_file (KatzeXbelItem* folder,
return TRUE;
}
/**
* katze_xbel_folder_from_data_dirs:
* @folder: An empty folder.
* @file: A relative path to a file.
* @full_path: return location for the full path of the file or %NULL
* @error: return location for a GError or %NULL
*
* Tries to load @file from the user data dir or any of the system data dirs.
*
* Return value: %TRUE on success or %FALSE when an error occured.
**/
gboolean
katze_xbel_folder_from_data_dirs (KatzeXbelItem* folder,
const gchar* file,
gchar** full_path,
GError** error)
{
g_return_val_if_fail (katze_xbel_folder_is_empty (folder), FALSE);
g_return_val_if_fail (file, FALSE);
/* FIXME: Essentially unimplemented */
*error = g_error_new_literal (KATZE_XBEL_ERROR, KATZE_XBEL_ERROR_READ,
_("Malformed document."));
return FALSE;
}
static gchar*
katze_xbel_xml_element (const gchar* name,
const gchar* value)
@ -860,17 +834,7 @@ katze_xbel_item_to_data (KatzeXbelItem* item)
return markup;
}
/**
* katze_xbel_folder_to_data:
* @folder: A folder.
* @length: return location for the length of the created string or %NULL
* @error: return location for a GError or %NULL
*
* Retrieve the contents of @folder as a string.
*
* Return value: %TRUE on success or %FALSE when an error occured.
**/
gchar*
static gchar*
katze_xbel_folder_to_data (KatzeXbelItem* folder,
gsize* length,
GError** error)

View file

@ -155,20 +155,9 @@ katze_xbel_folder_from_file (KatzeXbelItem* folder,
const gchar* file,
GError** error);
gboolean
katze_xbel_folder_from_data_dirs (KatzeXbelItem* folder,
const gchar* file,
gchar** full_path,
GError** error);
gchar*
katze_xbel_item_to_data (KatzeXbelItem* item);
gchar*
katze_xbel_folder_to_data (KatzeXbelItem* folder,
gsize* length,
GError** error);
gboolean
katze_xbel_folder_to_file (KatzeXbelItem* folder,
const gchar* file,

View file

@ -351,38 +351,6 @@ midori_web_list_add_item_cb (KatzeArray* trash,
}
}
static void
midori_browser_session_cb (MidoriBrowser* browser,
gpointer arg1,
KatzeXbelItem* session)
{
gchar* config_path;
gchar* config_file;
GError* error;
config_path = g_build_filename (g_get_user_config_dir (),
PACKAGE_NAME, NULL);
g_mkdir_with_parents (config_path, 0755);
config_file = g_build_filename (config_path, "session.xbel", NULL);
error = NULL;
if (!katze_xbel_folder_to_file (session, config_file, &error))
{
g_warning (_("The session couldn't be saved. %s"), error->message);
g_error_free (error);
}
g_free (config_file);
g_free (config_path);
}
static void
midori_browser_weak_notify_cb (MidoriBrowser* browser,
KatzeXbelItem* session)
{
g_object_disconnect (browser, "any-signal",
G_CALLBACK (midori_browser_session_cb), session, NULL);
}
static gchar*
_simple_xml_element (const gchar* name,
const gchar* value)
@ -464,6 +432,38 @@ katze_array_to_file (KatzeArray* array,
return TRUE;
}
static void
midori_browser_session_cb (MidoriBrowser* browser,
gpointer arg1,
KatzeArray* session)
{
gchar* config_path;
gchar* config_file;
GError* error;
config_path = g_build_filename (g_get_user_config_dir (),
PACKAGE_NAME, NULL);
g_mkdir_with_parents (config_path, 0755);
config_file = g_build_filename (config_path, "session.xbel", NULL);
error = NULL;
if (!katze_array_to_file (session, config_file, &error))
{
g_warning (_("The session couldn't be saved. %s"), error->message);
g_error_free (error);
}
g_free (config_file);
g_free (config_path);
}
static void
midori_browser_weak_notify_cb (MidoriBrowser* browser,
KatzeXbelItem* session)
{
g_object_disconnect (browser, "any-signal",
G_CALLBACK (midori_browser_session_cb), session, NULL);
}
int
main (int argc,
char** argv)
@ -711,7 +711,7 @@ main (int argc,
midori_app_add_browser (app, browser);
gtk_widget_show (GTK_WIDGET (browser));
KatzeXbelItem* session = midori_browser_get_proxy_xbel_folder (browser);
KatzeArray* session = midori_browser_get_proxy_xbel_array (browser);
n = katze_xbel_folder_get_n_items (_session);
for (i = 0; i < n; i++)
{

View file

@ -79,7 +79,7 @@ struct _MidoriBrowser
GList* tab_titles;
GList* close_buttons;
KatzeXbelItem* proxy_xbel_folder;
KatzeArray* proxy_xbel_array;
KatzeArray* trash;
KatzeArray* search_engines;
};
@ -800,14 +800,14 @@ midori_browser_tab_destroy_cb (GtkWidget* widget,
KatzeXbelItem* xbel_item;
const gchar* uri;
if (browser->proxy_xbel_folder && MIDORI_IS_WEB_VIEW (widget))
if (browser->proxy_xbel_array && MIDORI_IS_WEB_VIEW (widget))
{
xbel_item = midori_web_view_get_proxy_xbel_item (
MIDORI_WEB_VIEW (widget));
uri = katze_xbel_bookmark_get_href (xbel_item);
if (browser->trash && uri && *uri)
katze_array_add_item (browser->trash, xbel_item);
katze_xbel_folder_remove_item (browser->proxy_xbel_folder, xbel_item);
katze_array_remove_item (browser->proxy_xbel_array, xbel_item);
katze_xbel_item_unref (xbel_item);
}
@ -935,12 +935,12 @@ _midori_browser_add_tab (MidoriBrowser* browser,
tab_title = midori_web_view_get_proxy_tab_title (MIDORI_WEB_VIEW (widget));
menuitem = midori_web_view_get_proxy_menu_item (MIDORI_WEB_VIEW (widget));
if (browser->proxy_xbel_folder)
if (browser->proxy_xbel_array)
{
xbel_item = midori_web_view_get_proxy_xbel_item (
MIDORI_WEB_VIEW (widget));
katze_xbel_item_ref (xbel_item);
katze_xbel_folder_append_item (browser->proxy_xbel_folder, xbel_item);
katze_array_add_item (browser->proxy_xbel_array, xbel_item);
}
g_object_connect (widget,
@ -991,14 +991,13 @@ _midori_browser_add_tab (MidoriBrowser* browser,
gtk_image_new_from_pixbuf (icon));
g_object_unref (icon);
if (browser->proxy_xbel_folder)
if (browser->proxy_xbel_array)
{
xbel_item = katze_xbel_bookmark_new ();
katze_xbel_item_set_title (xbel_item, title);
katze_xbel_bookmark_set_href (xbel_item,
_midori_browser_get_tab_uri (browser, widget));
katze_xbel_folder_append_item (browser->proxy_xbel_folder,
xbel_item);
katze_array_add_item (browser->proxy_xbel_array, xbel_item);
}
}
g_object_set_data (G_OBJECT (widget), "browser-tab-icon", tab_icon);
@ -3619,8 +3618,8 @@ midori_browser_dispose (GObject* object)
MidoriBrowser* browser = MIDORI_BROWSER (object);
/* We are done, the session mustn't change anymore */
if (browser->proxy_xbel_folder)
katze_object_assign (browser->proxy_xbel_folder, NULL);
if (browser->proxy_xbel_array)
katze_object_assign (browser->proxy_xbel_array, NULL);
G_OBJECT_CLASS (midori_browser_parent_class)->dispose (object);
}
@ -4258,10 +4257,10 @@ midori_browser_get_current_web_view (MidoriBrowser* browser)
}
/**
* midori_browser_get_proxy_xbel_folder:
* midori_browser_get_proxy_xbel_array:
* @browser: a #MidoriBrowser
*
* Retrieves a proxy xbel folder representing the respective proxy xbel items
* Retrieves a proxy xbel array representing the respective proxy xbel items
* of the present web views that can be used for session management.
*
* The folder is created on the first call and will be updated to reflect
@ -4272,19 +4271,19 @@ midori_browser_get_current_web_view (MidoriBrowser* browser)
* Note: Calling this function doesn't add a reference and the browser
* may release its reference at some point.
*
* Return value: the proxy #KatzeXbelItem
* Return value: the proxy #KatzeArray
**/
KatzeXbelItem*
midori_browser_get_proxy_xbel_folder (MidoriBrowser* browser)
KatzeArray*
midori_browser_get_proxy_xbel_array (MidoriBrowser* browser)
{
g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
if (!browser->proxy_xbel_folder)
if (!browser->proxy_xbel_array)
{
browser->proxy_xbel_folder = katze_xbel_folder_new ();
browser->proxy_xbel_array = katze_array_new (KATZE_TYPE_XBEL_ITEM);
/* FIXME: Fill in xbel items of all present web views */
}
return browser->proxy_xbel_folder;
return browser->proxy_xbel_array;
}
/**

View file

@ -113,8 +113,8 @@ midori_browser_get_current_tab (MidoriBrowser* browser);
GtkWidget*
midori_browser_get_current_web_view (MidoriBrowser* browser);
KatzeXbelItem*
midori_browser_get_proxy_xbel_folder (MidoriBrowser* browser);
KatzeArray*
midori_browser_get_proxy_xbel_array (MidoriBrowser* browser);
void
midori_browser_quit (MidoriBrowser* browser);