Commit 8a4f3d6a authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

Separate out the new launcher functionality and support that in the

Mon Mar 11 19:55:21 2002  George Lebl <jirka@5z.com>

	* gnome-desktop-item-edit.c, menu-ditem.[ch], menu.c,
	  panel-util.[ch]:  Separate out the new launcher functionality
	  and support that in the desktop item edit thingie.
parent 3d169628
Mon Mar 11 19:55:21 2002 George Lebl <jirka@5z.com>
* gnome-desktop-item-edit.c, menu-ditem.[ch], menu.c,
panel-util.[ch]: Separate out the new launcher functionality
and support that in the desktop item edit thingie.
Mon Mar 11 17:48:16 2002 George Lebl <jirka@5z.com>
* panel-util.[ch], menu-ditem.c: fix the writable checking to handle
......
......@@ -20,6 +20,15 @@
GSList *applets;
static int dialogs = 0;
static gboolean create_new = FALSE;
struct poptOption options [] = {
{ "create-new", '\0', POPT_ARG_NONE,
&create_new, 0, N_("Create new file in the given directory"), NULL },
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0}
};
static void
dialog_destroyed (GtkWidget *dialog, gpointer data)
......@@ -41,7 +50,9 @@ main(int argc, char * argv[])
program = gnome_program_init ("gnome-desktop-item-edit", VERSION,
LIBGNOMEUI_MODULE,
argc, argv, NULL);
argc, argv,
GNOME_PARAM_POPT_TABLE, options,
NULL);
g_object_get (G_OBJECT (program),
GNOME_PARAM_POPT_CONTEXT, &ctx,
NULL);
......@@ -82,16 +93,33 @@ main(int argc, char * argv[])
if (gnome_vfs_get_file_info
(uri, info, GNOME_VFS_FILE_INFO_DEFAULT) != GNOME_VFS_OK) {
g_free (uri);
continue;
/* FIXME: we now assume these are uris, this is all
* somewhat broken */
/* ok, this doesn't exist, really */
if (is_ext (desktops[i], ".directory")) {
char *dirname = g_path_get_dirname (desktops[i]);
char *basename = g_path_get_basename (dirname);
dlg = panel_edit_direntry (dirname, basename);
g_free (basename);
g_free (dirname);
} else {
char *dirname = g_path_get_dirname (desktops[i]);
dlg = panel_edit_dentry (desktops[i], dirname);
g_free (dirname);
}
}
}
g_print ("BLAM!\n");
if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
char *basename = g_path_get_basename (desktops[i]);
dlg = panel_edit_direntry (uri, basename);
g_free (basename);
} else {
if (dlg == NULL &&
info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
if (create_new) {
dlg = panel_new_launcher (uri);
} else {
char *basename = g_path_get_basename (desktops[i]);
dlg = panel_edit_direntry (uri, basename);
g_free (basename);
}
} else if (dlg == NULL) {
char *dirname = g_path_get_dirname (uri);
dlg = panel_edit_dentry (uri, dirname);
g_free (dirname);
......
......@@ -141,6 +141,9 @@ is_item_writable (const char *loc, const char *dir)
else
return FALSE;
}
/* huh? */
return FALSE;
}
static void
......@@ -247,10 +250,6 @@ panel_edit_direntry (const char *dir, const char *dir_name)
ditem = gnome_desktop_item_new_from_uri (dirfile,
0 /* flags */,
NULL /* error */);
if (ditem == NULL) {
g_free (dirfile);
return NULL;
}
/* watch the enum at the top of the file */
dialog = gtk_dialog_new_with_buttons (_("Desktop entry properties"),
......@@ -350,3 +349,136 @@ panel_edit_direntry (const char *dir, const char *dir_name)
return dialog;
}
/* replaces '/' with returns _'s, originally from gmenu */
static void
validate_for_filename (char *file)
{
char *ptr;
g_return_if_fail (file != NULL);
ptr = file;
while (*ptr != '\0') {
if (*ptr == '/')
*ptr = '_';
ptr++;
}
}
static void
really_add_new_menu_item (GtkWidget *d, int response, gpointer data)
{
GnomeDItemEdit *dedit = GNOME_DITEM_EDIT(data);
char *dir = g_object_get_data (G_OBJECT (d), "dir");
GnomeDesktopItem *ditem;
GError *error = NULL;
int i;
char *name, *loc;
if (response != GTK_RESPONSE_OK) {
gtk_widget_destroy (d);
return;
}
g_return_if_fail (dir != NULL);
panel_push_window_busy (d);
ditem = gnome_ditem_edit_get_ditem (dedit);
if ((gnome_desktop_item_get_entry_type (ditem) == GNOME_DESKTOP_ITEM_TYPE_APPLICATION &&
string_empty (gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_EXEC))) ||
(gnome_desktop_item_get_entry_type (ditem) == GNOME_DESKTOP_ITEM_TYPE_LINK &&
string_empty (gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_URL)))) {
gnome_desktop_item_unref (ditem);
panel_error_dialog ("cannot_create_launcher",
_("Cannot create the launcher.\n\n"
"No command or url specified."));
return;
}
/* assume we are making a new file */
name = g_strdup (gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_NAME));
validate_for_filename (name);
loc = g_strdup_printf ("%s/%s.desktop", dir, name);
i = 2;
while (panel_uri_exists (loc)) {
g_free (loc);
/* FIXME: test for schema:basename.desktop as well
* here!!!! */
loc = g_strdup_printf ("%s/%s%d.desktop",
dir, name,
i ++);
}
gnome_desktop_item_set_location_file (ditem, loc);
g_free (name);
error = NULL;
gnome_desktop_item_save (ditem,
NULL /* under */,
TRUE /* force */,
&error);
if (error != NULL) {
panel_error_dialog ("cannot_save_menu_item" /* class */,
_("Cannot save menu item to disk, "
"the following error occured:\n\n"
"%s"),
error->message);
g_clear_error (&error);
}
gnome_desktop_item_unref (ditem);
panel_pop_window_busy (d);
gtk_widget_destroy (d);
g_free (loc);
}
GtkWidget *
panel_new_launcher (const char *item_loc)
{
GtkWidget *dialog;
GtkWidget *dee;
dialog = gtk_dialog_new_with_buttons (_("Create menu item"),
NULL /* parent */,
0 /* flags */,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OK,
GTK_RESPONSE_OK,
NULL);
gtk_window_set_wmclass (GTK_WINDOW (dialog),
"create_menu_item", "Panel");
dee = gnome_ditem_edit_new ();
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), dee,
TRUE, TRUE, GNOME_PAD_SMALL);
gnome_ditem_edit_set_entry_type (GNOME_DITEM_EDIT (dee),
"Application");
g_object_set_data_full (G_OBJECT (dialog), "dir",
g_strdup (item_loc),
(GDestroyNotify)g_free);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (really_add_new_menu_item),
dee);
gtk_dialog_set_default_response (GTK_DIALOG(dialog),
GTK_RESPONSE_OK);
gtk_widget_show_all (dialog);
gnome_ditem_edit_grab_focus (GNOME_DITEM_EDIT (dee));
return dialog;
}
......@@ -4,6 +4,7 @@ G_BEGIN_DECLS
GtkWidget * panel_edit_dentry (const char *loc, const char *dir);
GtkWidget * panel_edit_direntry (const char *dir, const char *dir_name);
GtkWidget * panel_new_launcher (const char *item_loc);
G_END_DECLS
......
......@@ -901,132 +901,10 @@ load_icons_handler_again:
return TRUE;
}
/* replaces '/' with returns _'s, originally from gmenu */
static void
validate_for_filename (char *file)
{
char *ptr;
g_return_if_fail (file != NULL);
ptr = file;
while (*ptr != '\0') {
if (*ptr == '/')
*ptr = '_';
ptr++;
}
}
static void
really_add_new_menu_item (GtkWidget *d, int response, gpointer data)
{
GnomeDItemEdit *dedit = GNOME_DITEM_EDIT(data);
char *dir = g_object_get_data (G_OBJECT (d), "dir");
GnomeDesktopItem *ditem;
GError *error = NULL;
int i;
char *name, *loc;
if (response != GTK_RESPONSE_OK) {
gtk_widget_destroy (d);
return;
}
g_return_if_fail (dir != NULL);
panel_push_window_busy (d);
ditem = gnome_ditem_edit_get_ditem (dedit);
if ((gnome_desktop_item_get_entry_type (ditem) == GNOME_DESKTOP_ITEM_TYPE_APPLICATION &&
string_empty (gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_EXEC))) ||
(gnome_desktop_item_get_entry_type (ditem) == GNOME_DESKTOP_ITEM_TYPE_LINK &&
string_empty (gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_URL)))) {
gnome_desktop_item_unref (ditem);
panel_error_dialog ("cannot_create_launcher",
_("Cannot create the launcher.\n\n"
"No command or url specified."));
return;
}
/* assume we are making a new file */
name = g_strdup (gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_NAME));
validate_for_filename (name);
loc = g_strdup_printf ("%s/%s.desktop", dir, name);
i = 2;
while (g_file_test (loc, G_FILE_TEST_EXISTS)) {
g_free (loc);
loc = g_strdup_printf ("%s/%s%d.desktop",
dir, name,
i ++);
}
gnome_desktop_item_set_location_file (ditem, loc);
g_free (name);
error = NULL;
gnome_desktop_item_save (ditem,
NULL /* under */,
TRUE /* force */,
&error);
if (error != NULL) {
panel_error_dialog ("cannot_save_menu_item" /* class */,
_("Cannot save menu item to disk, "
"the following error occured:\n\n"
"%s"),
error->message);
g_clear_error (&error);
}
gnome_desktop_item_unref (ditem);
panel_pop_window_busy (d);
gtk_widget_destroy (d);
g_free (loc);
}
static void
add_new_app_to_menu (GtkWidget *widget, const char *item_loc)
{
GtkWidget *dialog;
GtkWidget *dee;
dialog = gtk_dialog_new_with_buttons (_("Create menu item"),
NULL /* parent */,
0 /* flags */,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OK,
GTK_RESPONSE_OK,
NULL);
gtk_window_set_wmclass (GTK_WINDOW (dialog),
"create_menu_item", "Panel");
dee = gnome_ditem_edit_new ();
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), dee,
TRUE, TRUE, GNOME_PAD_SMALL);
gnome_ditem_edit_set_entry_type (GNOME_DITEM_EDIT (dee),
"Application");
g_object_set_data_full (G_OBJECT (dialog), "dir",
g_strdup (item_loc),
(GDestroyNotify)g_free);
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (really_add_new_menu_item),
dee);
gtk_dialog_set_default_response (GTK_DIALOG(dialog),
GTK_RESPONSE_OK);
gtk_widget_show_all (dialog);
gnome_ditem_edit_grab_focus (GNOME_DITEM_EDIT (dee));
panel_new_launcher (item_loc);
}
static void
......
......@@ -1349,9 +1349,31 @@ internal_panel_is_uri_writable (const char *uri, gboolean recurse)
gboolean
panel_is_uri_writable (const char *uri)
{
g_return_val_if_fail (uri != NULL, FALSE);
internal_panel_is_uri_writable (uri, TRUE /* recurse */);
}
gboolean
panel_uri_exists (const char *uri)
{
GnomeVFSURI *suri;
gboolean ret;
g_return_val_if_fail (uri != NULL, FALSE);
suri = gnome_vfs_uri_new (uri);
/* eek */
g_return_val_if_fail (suri != NULL, FALSE);
ret = gnome_vfs_uri_exists (suri);
gnome_vfs_uri_unref (suri);
return ret;
}
#if 0
/* hmmm, we need to use this I think to add a battery applet
* -George */
......
......@@ -123,6 +123,7 @@ void panel_signal_connect_object_while_alive (GObject *object,
gboolean panel_ensure_dir (const char *dirname);
gboolean panel_is_uri_writable (const char *uri);
gboolean panel_uri_exists (const char *uri);
/* GnomeVFS reading utils */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment