1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/*
* transmission-remote-gtk - A GTK RPC client to Transmission
* Copyright (C) 2011 Alan Fitton
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <json-glib/json-glib.h>
#ifdef HAVE_LIBUNIQUE
#include <unique/unique.h>
#endif
#include "trg-main-window.h"
#include "trg-client.h"
#ifdef HAVE_LIBUNIQUE
#define TRG_LIBUNIQUE_DOMAIN "uk.org.eth0.trg"
enum {
COMMAND_0,
COMMAND_ADD
};
static UniqueResponse
message_received_cb(UniqueApp * app G_GNUC_UNUSED,
gint command,
UniqueMessageData * message,
guint time_, gpointer user_data)
{
TrgMainWindow *win;
UniqueResponse res;
gchar **uris;
win = TRG_MAIN_WINDOW(user_data);
switch (command) {
case UNIQUE_ACTIVATE:
gtk_window_set_screen(GTK_WINDOW(user_data),
unique_message_data_get_screen(message));
gtk_window_present_with_time(GTK_WINDOW(user_data), time_);
res = UNIQUE_RESPONSE_OK;
break;
case COMMAND_ADD:
uris = unique_message_data_get_uris(message);
res =
trg_add_from_filename(win,
uris) ? UNIQUE_RESPONSE_OK :
UNIQUE_RESPONSE_FAIL;
break;
default:
res = UNIQUE_RESPONSE_OK;
break;
}
return res;
}
#endif
static gboolean should_be_minimised(int argc, char *argv[])
{
int i;
for(i = 1; i < argc; i++)
if (!g_strcmp0(argv[i], "-m") || !g_strcmp0(argv[i], "--minimized"))
return TRUE;
return FALSE;
}
int main(int argc, char *argv[])
{
int returnValue = EXIT_SUCCESS;
TrgMainWindow *window;
TrgClient *client;
#ifdef HAVE_LIBUNIQUE
UniqueApp *app = NULL;
gboolean withUnique;
#endif
#ifdef DEBUG
//GMemVTable gmvt = {malloc,realloc,free,calloc,malloc,realloc};
//g_mem_set_vtable(&gmvt);
g_mem_set_vtable(glib_mem_profiler_table);
g_mem_profile();
#endif
g_type_init();
g_thread_init(NULL);
gtk_init(&argc, &argv);
g_set_application_name (PACKAGE_NAME);
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
#ifdef HAVE_LIBUNIQUE
if ((withUnique = g_getenv("TRG_NOUNIQUE") == NULL))
app = unique_app_new_with_commands(TRG_LIBUNIQUE_DOMAIN, NULL,
"add", COMMAND_ADD, NULL);
if (withUnique && unique_app_is_running(app)) {
UniqueCommand command;
UniqueResponse response;
UniqueMessageData *message;
if (argc > 1) {
/* Turn the arguments into a null terminated array for libunique
* exclude the first (executable name).
*/
gchar **files = g_new0(gchar *, argc);
int i;
for (i = 1; i < argc; i++)
files[i - 1] = argv[i];
command = COMMAND_ADD;
message = unique_message_data_new();
unique_message_data_set_uris(message, files);
g_free(files);
} else {
command = UNIQUE_ACTIVATE;
message = NULL;
}
response = unique_app_send_message(app, command, message);
unique_message_data_free(message);
if (response != UNIQUE_RESPONSE_OK)
returnValue = EXIT_FAILURE;
} else {
#endif
client = trg_client_new();
curl_global_init(CURL_GLOBAL_ALL);
window = trg_main_window_new(client, should_be_minimised(argc, argv));
#ifdef HAVE_LIBUNIQUE
if (withUnique) {
unique_app_watch_window(app, GTK_WINDOW(window));
g_signal_connect(app, "message-received",
G_CALLBACK(message_received_cb), window);
}
#endif
auto_connect_if_required(window, client);
gtk_main();
curl_global_cleanup();
#ifdef HAVE_LIBUNIQUE
}
if (withUnique)
g_object_unref(app);
#endif
return returnValue;
}
|