source: trunk/third/gnome-panel/gnome-panel/gnome-desktop-item-edit.c @ 18631

Revision 18631, 4.5 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18630, which included commits to RCS files with non-trunk default branches.
Line 
1#include "config.h"
2#include <stdio.h>
3#include <stdlib.h>
4
5#include <libgnome/libgnome.h>
6#include <libgnomeui/libgnomeui.h>
7
8#include <libgnomevfs/gnome-vfs-mime.h>
9#include <libgnomevfs/gnome-vfs-uri.h>
10#include <libgnomevfs/gnome-vfs-ops.h>
11#include <libgnomevfs/gnome-vfs-directory.h>
12#include <libgnomevfs/gnome-vfs-utils.h>
13
14#include "menu-ditem.h"
15#include "panel-util.h"
16
17#include "nothing.cP"
18
19/* Just so we can link with panel-util.c for the convert keys stuff*/
20GSList *applets;
21
22static int dialogs = 0;
23static gboolean create_new = FALSE;
24
25struct poptOption options [] = {
26        { "create-new", '\0', POPT_ARG_NONE,
27          &create_new, 0, N_("Create new file in the given directory"), NULL },
28        POPT_AUTOHELP
29        { NULL, 0, 0, NULL, 0}
30};
31
32
33static void
34dialog_destroyed (GtkWidget *dialog, gpointer data)
35{
36        dialogs --;
37
38        if (dialogs <= 0)
39                gtk_main_quit ();
40}
41
42static gboolean
43is_an_uri (const char *uri)
44{
45        GnomeVFSURI *suri = gnome_vfs_uri_new (uri);
46        if (suri == NULL)
47                return FALSE;
48        gnome_vfs_uri_unref (suri);
49        return TRUE;
50}
51
52static char *
53get_uri (const char *arg)
54{
55        char *uri;
56
57        if (is_an_uri (arg))
58                return gnome_vfs_make_uri_canonical (arg);
59
60        if (g_path_is_absolute (arg)) {
61                uri = gnome_vfs_get_uri_from_local_path (arg);
62        } else {
63                char *cur = g_get_current_dir ();
64                char *full = g_build_filename (cur, arg, NULL);
65                g_free (cur);
66                uri = gnome_vfs_get_uri_from_local_path (full);
67                g_free (full);
68        }
69
70        return uri;
71}
72
73int
74main (int argc, char * argv[])
75{
76        poptContext ctx;
77        GnomeProgram *program;
78        char **desktops;
79        int i;
80        GnomeVFSFileInfo *info;
81
82        program = gnome_program_init ("gnome-desktop-item-edit", VERSION,
83                                      LIBGNOMEUI_MODULE,
84                                      argc, argv,
85                                      GNOME_PARAM_POPT_TABLE, options,
86                                      NULL);
87        g_object_get (G_OBJECT (program),
88                      GNOME_PARAM_POPT_CONTEXT, &ctx,
89                      NULL);
90
91        desktops = (char **)poptGetArgs (ctx);
92
93        if (desktops == NULL ||
94            desktops[0] == NULL) {
95                fprintf (stderr, "gnome-desktop-item-edit: no file to edit\n");
96                return 0;
97        }
98
99        info = gnome_vfs_file_info_new ();
100
101        for (i = 0; desktops[i] != NULL; i++) {
102                char *uri = get_uri (desktops[i]);
103                GtkWidget *dlg = NULL;
104
105                gnome_vfs_file_info_clear (info);
106
107                if (gnome_vfs_get_file_info
108                    (uri, info, GNOME_VFS_FILE_INFO_DEFAULT) == GNOME_VFS_OK) {
109
110                        if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY && create_new) {
111                                dlg = panel_new_launcher (
112                                                uri, gdk_screen_get_default ());
113
114                        } else if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
115                                /* rerun this iteration with the .directory file */
116                                /* Note: No need to free, for one we can't free an
117                                 * individual member of desktops and secondly we
118                                 * will soon exit */
119                                desktops[i] =
120                                        g_build_path ("/", uri,
121                                                      ".directory", NULL);
122                                g_free (uri);
123                                i--;
124                                continue;
125
126                        } else if (info->type == GNOME_VFS_FILE_TYPE_REGULAR
127                                   && is_ext (desktops[i], ".directory")
128                                   && !create_new) {
129                                char *dirname = g_path_get_dirname (uri);
130                                dlg = panel_edit_direntry (dirname, NULL,
131                                                           gdk_screen_get_default ());
132                                g_free (dirname);
133                       
134                        } else if (info->type == GNOME_VFS_FILE_TYPE_REGULAR
135                                   && is_ext (desktops[i], ".desktop")
136                                   && !create_new) {
137                                char *dirname = g_path_get_dirname (uri);
138                                dlg = panel_edit_dentry (uri, dirname,
139                                                         gdk_screen_get_default ());
140                                g_free (dirname);
141                               
142                        } else {
143                                fprintf (stderr, "gnome-desktop-item-edit: %s "
144                                         "doesn't seem like a desktop item\n",
145                                         uri);
146                        }
147
148                } else if (is_ext (desktops[i], ".directory")
149                           && !create_new) {
150                        /* a non-existant file.  Well we can still edit that sort
151                         * of.  We will just create it new */
152                        char *dirname = g_path_get_dirname (uri);
153                        dlg = panel_edit_direntry (dirname, NULL,
154                                                   gdk_screen_get_default ());
155                        g_free (dirname);
156               
157                } else if (is_ext (desktops[i], ".desktop")
158                           && !create_new) {
159                        /* a non-existant file.  Well we can still edit that sort
160                         * of.  We will just create it new */
161                        /* FIXME: deal with issues of item existing in
162                         * another vfolder! */
163                        char *dirname = g_path_get_dirname (uri);
164                        dlg = panel_edit_dentry (uri, dirname,
165                                                 gdk_screen_get_default ());
166                        g_free (dirname);
167
168                } else {
169                        fprintf (stderr, "gnome-desktop-item-edit: %s does "
170                                 "not exist\n", uri);
171                }
172
173                if (dlg != NULL) {
174                        dialogs ++;
175                        g_signal_connect (G_OBJECT (dlg), "destroy",
176                                          G_CALLBACK (dialog_destroyed),
177                                          NULL);
178                }
179
180                g_free (uri);
181        }
182
183        gnome_vfs_file_info_unref (info);
184
185        if (dialogs > 0)
186                gtk_main ();
187
188        return 0;
189}
Note: See TracBrowser for help on using the repository browser.