Repository navigation
Expand file tree
/
Copy pathFeedReader.vala
More file actions
231 lines (190 loc) · 5.14 KB
/
Copy pathFeedReader.vala
File metadata and controls
231 lines (190 loc) · 5.14 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// This file is part of FeedReader.
//
// FeedReader 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 3 of the License, or
// (at your option) any later version.
//
// FeedReader 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 FeedReader. If not, see <http://www.gnu.org/licenses/>.
using GLib;
using Gtk;
namespace FeedReader {
public const string QUICKLIST_ABOUT_STOCK = N_("About FeedReader");
public class FeedReaderApp : Gtk.Application {
private MainWindow m_window;
private bool m_online = true;
private static FeedReaderApp? m_app = null;
public signal void callback(string content);
public new static FeedReaderApp get_default()
{
if(m_app == null)
m_app = new FeedReaderApp();
return m_app;
}
public bool isOnline()
{
return m_online;
}
public void setOnline(bool online)
{
m_online = online;
}
protected override void startup()
{
Logger.init("ui");
Logger.info("FeedReader " + AboutInfo.version);
base.startup();
}
public override void activate()
{
base.activate();
WebKit.WebContext.get_default().set_web_extensions_directory(Constants.INSTALL_PREFIX + "/" + Constants.INSTALL_LIBDIR);
if(m_window == null)
{
m_window = MainWindow.get_default();
m_window.set_icon_name("org.gnome.FeedReader");
Gtk.IconTheme.get_default().add_resource_path("/org/gnome/FeedReader/icons");
}
m_window.show_all();
m_window.present();
try
{
DBusConnection.connectSignals();
DBusConnection.get_default().updateBadge();
DBusConnection.get_default().checkOnlineAsync();
}
catch(GLib.Error e)
{
Logger.error("FeedReader.activate: %s".printf(e.message));
}
}
public override int command_line(ApplicationCommandLine command_line)
{
var args = command_line.get_arguments();
if(args.length > 1)
{
Logger.debug("FeedReader: callback %s".printf(args[1]));
callback(args[1]);
}
activate();
return 0;
}
protected override void shutdown()
{
Logger.debug("Shutdown!");
Gst.deinit();
base.shutdown();
}
public async void sync()
{
SourceFunc callback = sync.callback;
ThreadFunc<void*> run = () => {
try
{
DBusConnection.get_default().startSync();
}
catch(IOError e)
{
Logger.error("FeedReader.sync: " + e.message);
}
Idle.add((owned) callback);
return null;
};
new GLib.Thread<void*>("sync", run);
yield;
}
private FeedReaderApp()
{
GLib.Object(application_id: "org.gnome.FeedReader", flags: ApplicationFlags.HANDLES_COMMAND_LINE);
}
}
public static int main (string[] args)
{
try
{
var opt_context = new OptionContext();
opt_context.set_help_enabled(true);
opt_context.add_main_entries(options, null);
opt_context.parse(ref args);
}
catch(OptionError e)
{
print(e.message + "\n");
return 0;
}
if(version)
{
stdout.printf("Version: %s\n", AboutInfo.version);
stdout.printf("Git Commit: %s\n", Constants.GIT_SHA1);
return 0;
}
if(about)
{
show_about(args);
return 0;
}
if(media != null)
{
UtilsUI.playMedia(args, media);
return 0;
}
if(pingURL != null)
{
Logger.init("ui");
if(!Utils.ping(pingURL))
Logger.error("Ping failed");
return 0;
}
try
{
Gst.init_check(ref args);
}
catch(GLib.Error e)
{
Logger.error("Gst.init: " + e.message);
}
var app = FeedReaderApp.get_default();
app.run(args);
return 0;
}
private const GLib.OptionEntry[] options = {
{ "version", 0, 0, OptionArg.NONE, ref version, "FeedReader version number", null },
{ "about", 0, 0, OptionArg.NONE, ref about, "spawn about dialog", null },
{ "playMedia", 0, 0, OptionArg.STRING, ref media, "start media player with URL", "URL" },
{ "ping", 0, 0, OptionArg.STRING, ref pingURL, "test the ping function with given URL", "URL" },
{ null }
};
private static bool version = false;
private static bool about = false;
private static string? media = null;
private static string? pingURL = null;
static void show_about(string[] args)
{
Gtk.init(ref args);
Gtk.AboutDialog dialog = new Gtk.AboutDialog();
dialog.response.connect ((response_id) => {
if(response_id == Gtk.ResponseType.CANCEL || response_id == Gtk.ResponseType.DELETE_EVENT)
Gtk.main_quit();
});
dialog.artists = AboutInfo.artists;
dialog.authors = AboutInfo.authors;
dialog.documenters = null;
dialog.translator_credits = AboutInfo.translators;
dialog.program_name = AboutInfo.programmName;
dialog.comments = AboutInfo.comments;
dialog.copyright = AboutInfo.copyright;
dialog.version = AboutInfo.version;
dialog.logo_icon_name = AboutInfo.iconName;
dialog.license_type = Gtk.License.GPL_3_0;
dialog.wrap_license = true;
dialog.website = AboutInfo.website;
dialog.present();
Gtk.main();
}
}