~ubuntu-branches/ubuntu/lucid/libfm/lucid

« back to all changes in this revision

Viewing changes to src/gtk/fm-file-menu.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-04-11 12:58:35 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100411125835-x6ymkamnxae3blok
Tags: 0.1.9+git20100414-0ubuntu1
* New upstream snapshot (f5107fc..60a482a), close to the final release.
* debian/rules:
 - Enable demo executable
* debian/libfm0.install:
 - Install gio module
 - Install translations
* debian/libfm-gtk0.install:
 - Install the prefered applications chooser.
* Switch to dpkg-source 3.0 (quilt) format
* debian/patches/01-lxde-conf.patch: Use lxterminal for terminal by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *      fm-file-menu.c
3
 
 *      
 
3
 *
4
4
 *      Copyright 2009 PCMan <pcman.tw@gmail.com>
5
 
 *      
 
5
 *
6
6
 *      This program is free software; you can redistribute it and/or modify
7
7
 *      it under the terms of the GNU General Public License as published by
8
8
 *      the Free Software Foundation; either version 2 of the License, or
9
9
 *      (at your option) any later version.
10
 
 *      
 
10
 *
11
11
 *      This program is distributed in the hope that it will be useful,
12
12
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
14
 *      GNU General Public License for more details.
15
 
 *      
 
15
 *
16
16
 *      You should have received a copy of the GNU General Public License
17
17
 *      along with this program; if not, write to the Free Software
18
18
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25
25
 
26
26
#include <glib/gi18n-lib.h>
27
27
 
 
28
#include "fm.h"
28
29
#include "fm-config.h"
29
30
 
30
31
#include "fm-file-menu.h"
35
36
#include "fm-utils.h"
36
37
#include "fm-gtk-utils.h"
37
38
#include "fm-app-chooser-dlg.h"
 
39
#include "fm-archiver.h"
38
40
 
39
41
static void on_open(GtkAction* action, gpointer user_data);
40
42
static void on_open_with_app(GtkAction* action, gpointer user_data);
44
46
static void on_paste(GtkAction* action, gpointer user_data);
45
47
static void on_delete(GtkAction* action, gpointer user_data);
46
48
static void on_rename(GtkAction* action, gpointer user_data);
 
49
static void on_compress(GtkAction* action, gpointer user_data);
 
50
static void on_extract_here(GtkAction* action, gpointer user_data);
 
51
static void on_extract_to(GtkAction* action, gpointer user_data);
47
52
static void on_prop(GtkAction* action, gpointer user_data);
48
53
 
49
54
const char base_menu_xml[]=
60
65
  "<menuitem action='Del'/>"
61
66
  "<separator/>"
62
67
  "<menuitem action='Rename'/>"
 
68
/* TODO: implement symlink creation and "send to".
63
69
  "<menuitem action='Link'/>"
64
70
  "<menu action='SendTo'>"
65
71
  "</menu>"
 
72
*/
66
73
  "<separator/>"
67
74
  "<placeholder name='ph3'/>"
68
75
  "<separator/>"
82
89
    {"Rename", NULL, N_("Rename"), "F2", NULL, on_rename},
83
90
    {"Link", NULL, N_("Create Symlink"), NULL, NULL, NULL},
84
91
    {"SendTo", NULL, N_("Send To"), NULL, NULL, NULL},
 
92
    {"Compress", NULL, N_("Compress..."), NULL, NULL, on_compress},
 
93
    {"Extract", NULL, N_("Extract Here"), NULL, NULL, on_extract_here},
 
94
    {"Extract2", NULL, N_("Extract To..."), NULL, NULL, on_extract_to},
85
95
    {"Prop", GTK_STOCK_PROPERTIES, NULL, NULL, NULL, on_prop}
86
96
};
87
97
 
93
103
    if(menu->file_infos)
94
104
        fm_list_unref(menu->file_infos);
95
105
 
 
106
    if(menu->cwd)
 
107
        fm_path_unref(menu->cwd);
 
108
 
96
109
    g_object_unref(menu->act_grp);
97
110
    g_object_unref(menu->ui);
98
111
    g_slice_free(FmFileMenu, menu);
99
112
}
100
113
 
101
 
FmFileMenu* fm_file_menu_new_for_file(FmFileInfo* fi, gboolean auto_destroy)
 
114
FmFileMenu* fm_file_menu_new_for_file(FmFileInfo* fi, FmPath* cwd, gboolean auto_destroy)
102
115
{
103
116
    FmFileMenu* menu;
104
117
    FmFileInfoList* files = fm_file_info_list_new();
105
118
    fm_list_push_tail(files, fi);
106
 
    menu = fm_file_menu_new_for_files(files, auto_destroy);
 
119
    menu = fm_file_menu_new_for_files(files, cwd, auto_destroy);
107
120
    fm_list_unref(files);
108
121
    return menu;
109
122
}
110
123
 
111
 
FmFileMenu* fm_file_menu_new_for_files(FmFileInfoList* files, gboolean auto_destroy)
 
124
FmFileMenu* fm_file_menu_new_for_files(FmFileInfoList* files, FmPath* cwd, gboolean auto_destroy)
112
125
{
113
126
    GtkWidget* menu;
114
127
    GtkUIManager* ui;
124
137
    gtk_action_group_set_translation_domain(act_grp, GETTEXT_PACKAGE);
125
138
 
126
139
    data->file_infos = fm_list_ref(files);
 
140
    if(cwd)
 
141
        data->cwd = fm_path_ref(cwd);
127
142
 
128
143
    gtk_action_group_add_actions(act_grp, base_menu_actions, G_N_ELEMENTS(base_menu_actions), data);
129
144
    gtk_ui_manager_add_ui_from_string(ui, base_menu_xml, -1, NULL);
148
163
            for(l=apps;l;l=l->next)
149
164
            {
150
165
                GAppInfo* app = l->data;
151
 
                act = gtk_action_new(g_app_info_get_id(app), 
 
166
                act = gtk_action_new(g_app_info_get_id(app),
152
167
                            g_app_info_get_name(app),
153
 
                            g_app_info_get_description(app), 
 
168
                            g_app_info_get_description(app),
154
169
                            NULL);
155
170
                g_signal_connect(act, "activate", G_CALLBACK(on_open_with_app), data);
156
171
                gtk_action_set_gicon(act, g_app_info_get_icon(app));
157
172
                gtk_action_group_add_action(act_grp, act);
158
173
                /* associate the app info object with the action */
159
 
                g_object_set_data_full(act, "app", app, (GDestroyNotify)g_object_unref);
 
174
                g_object_set_qdata_full(G_OBJECT(act), fm_qdata_id, app, (GDestroyNotify)g_object_unref);
160
175
                g_string_append_printf(xml, "<menuitem action='%s'/>", g_app_info_get_id(app));
161
176
            }
162
177
 
163
178
            g_list_free(apps);
164
179
            if(use_sub)
165
180
            {
166
 
                g_string_append(xml, 
 
181
                g_string_append(xml,
167
182
                    "<separator/>"
168
183
                    "<menuitem action='OpenWith'/>"
169
184
                    "</menu>");
175
190
    else
176
191
        g_string_append(xml, "<menuitem action='OpenWith'/>");
177
192
    g_string_append(xml, "</placeholder></popup>");
 
193
 
 
194
    /* archiver integration */
 
195
    g_string_append(xml, "<popup><placeholder name='ph3'>");
 
196
    if(data->same_type)
 
197
    {
 
198
        FmArchiver* archiver = fm_archiver_get_default();
 
199
        if(archiver)
 
200
        {
 
201
            FmFileInfo* fi = (FmFileInfo*)fm_list_peek_head(data->file_infos);
 
202
            if(fm_archiver_is_mime_type_supported(archiver, fi->type->type))
 
203
            {
 
204
                if(data->cwd && archiver->extract_to_cmd)
 
205
                    g_string_append(xml, "<menuitem action='Extract'/>");
 
206
                if(archiver->extract_cmd)
 
207
                    g_string_append(xml, "<menuitem action='Extract2'/>");
 
208
            }
 
209
            else
 
210
                g_string_append(xml, "<menuitem action='Compress'/>");
 
211
        }
 
212
    }
 
213
    else
 
214
        g_string_append(xml, "<menuitem action='Compress'/>");
 
215
    g_string_append(xml, "</placeholder></popup>");
 
216
 
178
217
    gtk_ui_manager_add_ui_from_string(ui, xml->str, xml->len, NULL);
 
218
 
179
219
    g_string_free(xml, TRUE);
180
220
    return data;
181
221
}
213
253
    FmFileMenu* data = (FmFileMenu*)user_data;
214
254
    GList* l = fm_list_peek_head_link(data->file_infos);
215
255
    GError* err = NULL;
216
 
    fm_launch_files_simple(gtk_widget_get_toplevel(data->menu), NULL, l, data->folder_func, data->folder_func_data);
 
256
    fm_launch_files_simple(GTK_WINDOW(gtk_widget_get_toplevel(data->menu)), NULL, l, data->folder_func, data->folder_func_data);
217
257
}
218
258
 
219
259
static void open_with_app(FmFileMenu* data, GAppInfo* app)
221
261
    GdkAppLaunchContext* ctx;
222
262
    FmFileInfoList* files = data->file_infos;
223
263
    GList* l = fm_list_peek_head_link(files);
224
 
    char** uris = g_new0(char*, fm_list_get_length(files) + 1);
 
264
    GList* uris = NULL;
225
265
    int i;
226
266
    for(i=0; l; ++i, l=l->next)
227
267
    {
228
268
        FmFileInfo* fi = (FmFileInfo*)l->data;
229
269
        FmPath* path = fi->path;
230
270
        char* uri = fm_path_to_uri(path);
231
 
        uris[i] = uri;
 
271
        uris = g_list_prepend(uris, uri);
232
272
    }
 
273
    uris = g_list_reverse(uris);
233
274
 
234
275
    ctx = gdk_app_launch_context_new();
235
276
    gdk_app_launch_context_set_screen(ctx, gtk_widget_get_screen(data->menu));
240
281
    g_app_info_launch_uris(app, uris, ctx, NULL);
241
282
    g_object_unref(ctx);
242
283
 
243
 
    g_free(uris);
 
284
    g_list_foreach(uris, (GFunc)g_free, NULL);
 
285
    g_list_free(uris);
244
286
}
245
287
 
246
288
void on_open_with_app(GtkAction* action, gpointer user_data)
247
289
{
248
290
    FmFileMenu* data = (FmFileMenu*)user_data;
249
 
    GAppInfo* app = (GAppInfo*)g_object_get_data(action, "app");
 
291
    GAppInfo* app = (GAppInfo*)g_object_get_qdata(G_OBJECT(action), fm_qdata_id);
250
292
    g_debug("%s", gtk_action_get_name(action));
251
293
    open_with_app(data, app);
252
294
}
322
364
*/
323
365
}
324
366
 
 
367
void on_compress(GtkAction* action, gpointer user_data)
 
368
{
 
369
    FmFileMenu* data = (FmFileMenu*)user_data;
 
370
    FmPathList* files;
 
371
    GAppLaunchContext* ctx = gdk_app_launch_context_new();
 
372
    FmArchiver* archiver = fm_archiver_get_default();
 
373
    files = fm_path_list_new_from_file_info_list(data->file_infos);
 
374
    fm_archiver_create_archive(archiver, ctx, files);
 
375
    fm_list_unref(files);
 
376
    g_object_unref(ctx);
 
377
}
 
378
 
 
379
void on_extract_here(GtkAction* action, gpointer user_data)
 
380
{
 
381
    FmFileMenu* data = (FmFileMenu*)user_data;
 
382
    FmPathList* files;
 
383
    GAppLaunchContext* ctx = gdk_app_launch_context_new();
 
384
    FmArchiver* archiver = fm_archiver_get_default();
 
385
    files = fm_path_list_new_from_file_info_list(data->file_infos);
 
386
    fm_archiver_extract_archives_to(archiver, ctx, files, data->cwd);
 
387
    fm_list_unref(files);
 
388
    g_object_unref(ctx);
 
389
}
 
390
 
 
391
void on_extract_to(GtkAction* action, gpointer user_data)
 
392
{
 
393
    FmFileMenu* data = (FmFileMenu*)user_data;
 
394
    FmPathList* files;
 
395
    GAppLaunchContext* ctx = gdk_app_launch_context_new();
 
396
    FmArchiver* archiver = fm_archiver_get_default();
 
397
    files = fm_path_list_new_from_file_info_list(data->file_infos);
 
398
    fm_archiver_extract_archives(archiver, ctx, files);
 
399
    fm_list_unref(files);
 
400
    g_object_unref(ctx);
 
401
}
 
402
 
325
403
void on_prop(GtkAction* action, gpointer user_data)
326
404
{
327
405
    FmFileMenu* data = (FmFileMenu*)user_data;
338
416
    menu->folder_func = func;
339
417
    menu->folder_func_data = user_data;
340
418
}
 
419
 
 
420