~elementary-os/ubuntu-package-imports/file-roller-bionic

« back to all changes in this revision

Viewing changes to src/dlg-open-with.c

  • Committer: RabbitBot
  • Date: 2018-02-05 12:55:45 UTC
  • Revision ID: rabbitbot@elementary.io-20180205125545-nmwn0wosptxjg5ei
Initial import, version 3.26.2-3ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
 
 
3
/*
 
4
 *  File-Roller
 
5
 *
 
6
 *  Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 2 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
#include <string.h>
 
24
#include <gtk/gtk.h>
 
25
#include "file-utils.h"
 
26
#include "glib-utils.h"
 
27
#include "gtk-utils.h"
 
28
#include "fr-init.h"
 
29
#include "fr-window.h"
 
30
#include "dlg-open-with.h"
 
31
 
 
32
 
 
33
typedef struct {
 
34
        FrWindow *window;
 
35
        GList    *file_list;
 
36
} OpenData;
 
37
 
 
38
 
 
39
static void
 
40
app_chooser_response_cb (GtkDialog *dialog,
 
41
                         int        response_id,
 
42
                         gpointer   user_data)
 
43
{
 
44
        OpenData *o_data = user_data;
 
45
        GAppInfo *app_info;
 
46
 
 
47
        switch (response_id) {
 
48
        case GTK_RESPONSE_OK:
 
49
                app_info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
 
50
                if (app_info != NULL) {
 
51
                        fr_window_open_files_with_application (o_data->window, o_data->file_list, app_info);
 
52
                        g_object_unref (app_info);
 
53
                }
 
54
                g_free (o_data);
 
55
                gtk_widget_destroy (GTK_WIDGET (dialog));
 
56
                break;
 
57
 
 
58
        case GTK_RESPONSE_CANCEL:
 
59
        case GTK_RESPONSE_DELETE_EVENT:
 
60
                g_free (o_data);
 
61
                gtk_widget_destroy (GTK_WIDGET (dialog));
 
62
                break;
 
63
 
 
64
        default:
 
65
                break;
 
66
        }
 
67
}
 
68
 
 
69
 
 
70
void
 
71
dlg_open_with (FrWindow *window,
 
72
               GList    *file_list)
 
73
{
 
74
        OpenData  *o_data;
 
75
        GtkWidget *app_chooser;
 
76
 
 
77
        o_data = g_new0 (OpenData, 1);
 
78
        o_data->window = window;
 
79
        o_data->file_list = file_list;
 
80
 
 
81
        app_chooser = gtk_app_chooser_dialog_new (GTK_WINDOW (window),
 
82
                                                  GTK_DIALOG_MODAL,
 
83
                                                  G_FILE (file_list->data));
 
84
        g_signal_connect (app_chooser,
 
85
                          "response",
 
86
                          G_CALLBACK (app_chooser_response_cb),
 
87
                          o_data);
 
88
        gtk_widget_show (app_chooser);
 
89
}
 
90
 
 
91
 
 
92
void
 
93
open_with_cb (GtkWidget *widget,
 
94
              void      *callback_data)
 
95
{
 
96
        FrWindow *window = callback_data;
 
97
        GList    *file_list;
 
98
 
 
99
        file_list = fr_window_get_file_list_selection (window, FALSE, NULL);
 
100
        if (file_list == NULL)
 
101
                return;
 
102
 
 
103
        fr_window_open_files (window, file_list, TRUE);
 
104
        _g_string_list_free (file_list);
 
105
}