48
43
// Unload all the plugins
49
44
void Gloobus::end()
51
m_PManager->unload_plugins(); // Unload Plugins
54
void Gloobus::show_preview(char * target)
57
gloobusWin * win = new gloobusWin();
58
win->create_window( DEFAULT_WIDTH, DEFAULT_HEIGHT );
61
g_signal_connect (win->get_window_pointer(), "key-press-event",
62
G_CALLBACK(key_press), NULL);
64
win->create_toolbar();
65
g_signal_connect (win->get_toolbar_pointer(),"key-press-event",
66
G_CALLBACK(key_press), NULL);
71
// check relative path:
72
if (filename.c_str()[0] != '/') {
73
filename = "./" + filename;
77
if (filename.c_str()[filename.size()-1] == '/') {
78
filename = filename.substr(0,filename.size()-1);
81
g_debug("Getting file from clipboard");
82
GtkClipboard *clip = gtk_clipboard_get ( GDK_SELECTION_CLIPBOARD );
83
gchar **uri = gtk_clipboard_wait_for_uris ( clip );
85
m_error = g_error_new(g_quark_from_string ("Gloobus"), 1,
86
_("There is no file in clipboard"));
88
filename = g_filename_from_uri(uri[0], NULL, NULL);
91
init( filename , win );
92
load_folder_filenames();
94
g_debug("Filename: %s", filename.c_str());
95
if( !search_actual_filename()) {
96
m_error = g_error_new(g_quark_from_string ("Gloobus"), 2,
98
} else if(create_plugin()) {
100
int w = get_width () + SHADOW_WIDTH * 2;
101
int h = get_height() + SHADOW_WIDTH * 2 + BOTTOM_HEIGHT + HEADER_HEIGHT;
103
win->set_size( w, h );
104
win->set_title( filename );
105
win->add_common_buttons();
108
draw_plugin (); //Its drawn on top so buttons in fullscreen are hidden
110
m_error = m_gloobus_interface->get_error();
118
destroy_plugin();//Destroy current plugin
119
end(); //Unload All plugins before leave
122
void Gloobus::show_supported_filetypes ( )
124
m_PManager->load_plugins (); //Plugin manager loads the .so
125
m_PManager->show_supported_filetypes();
126
m_PManager->unload_plugins(); // Unload Plugins
129
void Gloobus::show_help ( )
133
" gloobus-preview [%s...] [URI]\n\n",
134
_("Usage"), _("OPTION") );
138
"If URI is not provided Gloobus-Preview checks clipboard "
141
printf("%s:\n", _("Help options") );
142
printf(" -h, --help %s\n",
143
_("Show help options") );
145
printf("%s:\n", _("Application options") );
146
printf(" -d, --debug %s\n",
147
_("Show debug messages") );
148
printf(" --show-supported-filetypes %s\n",
149
_("Show supported filetypes") );
154
void Gloobus::show_error( bool idefault ) {
155
//g_warning(m_error->message);
156
if(idefault || m_gloobus_interface ) {
157
g_debug("Loading iDefault");
160
m_gloobus_interface = new iDefault();
161
m_gloobus_interface->set_filename(m_filename);
162
m_gloobus_interface->load();
164
m_gwindow->set_size(get_width() + SHADOW_WIDTH*2, get_height()+ SHADOW_WIDTH*2 + BOTTOM_HEIGHT+HEADER_HEIGHT);
165
m_gwindow->set_title (m_filename);
166
m_gwindow->add_common_buttons ();
167
m_gwindow->show_all ();
171
g_debug("Loading error dialog");
172
gtk_widget_destroy (GTK_WIDGET(m_gwindow->get_container_pointer()));
173
gtk_widget_destroy (GTK_WIDGET(m_gwindow->get_toolbar_pointer()));
175
m_gwindow->create_toolbar();
176
m_gwindow->create_container();
179
384 + SHADOW_WIDTH * 2,
180
128 + SHADOW_WIDTH * 2 /*+ BOTTOM_HEIGHT*/ + HEADER_HEIGHT);
181
m_gwindow->set_title(m_filename);
182
m_gwindow->add_common_buttons();
183
//GtkWidget * box = gtk_vbox_new(false, 0);
184
GtkWidget * icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_ERROR,
185
GTK_ICON_SIZE_DIALOG);
186
GtkWidget * label = gtk_label_new(m_error->message);
188
PangoAttrList *info_attrs = pango_attr_list_new();
189
pango_attr_list_insert(info_attrs,
190
pango_attr_foreground_new(53889,14927,253));
191
pango_attr_list_insert(info_attrs,
192
pango_attr_weight_new(PANGO_WEIGHT_BOLD));
193
pango_attr_list_insert(info_attrs, pango_attr_size_new(14*PANGO_SCALE));
194
gtk_widget_set_size_request(label, 256, 128);
195
gtk_label_set_attributes(GTK_LABEL(label), info_attrs);
196
gtk_label_set_line_wrap(GTK_LABEL(label), true);
197
gtk_misc_set_alignment(GTK_MISC(label), 0 , 0.5);
199
// GTK_ICON_SIZE_DIALOG is 40, for all themes?
200
// 128-40 /2 = 44 - place icon in the middle
201
gtk_fixed_put(GTK_FIXED(m_gwindow->get_container_pointer()),
202
icon, SHADOW_WIDTH+44, HEADER_HEIGHT + SHADOW_WIDTH + 44);
203
gtk_fixed_put(GTK_FIXED(m_gwindow->get_container_pointer()),
204
label, SHADOW_WIDTH+128, HEADER_HEIGHT + SHADOW_WIDTH);
205
gtk_widget_show_all(icon);
206
gtk_widget_show_all(label);
207
m_gwindow->show_all();
46
PluginManager::unload_plugins();
211
49
// =============================== CREATE PLUGIN ======================= //
214
52
// can be called with directly on this variable
215
53
bool Gloobus::create_plugin( )
220
m_plugin_name = m_PManager->search_for_plugin(m_filename);
221
m_class = m_PManager->get_classtype ();
222
g_debug("Creating plugin class: %s",m_class.c_str());
224
if(m_class == "image") {
225
g_debug("IMAGE (%s)",m_plugin_name.c_str());
226
m_gloobus_interface = factory_image[m_plugin_name.c_str()](); //Polymorphism
227
} else if(m_class == "music") {
228
g_debug("MUSIC (%s)",m_plugin_name.c_str());
229
m_gloobus_interface = factory_music[m_plugin_name.c_str()](); //Polymorphism
230
} else if(m_class == "text") {
231
g_debug("TEXT (%s)",m_plugin_name.c_str());
232
m_gloobus_interface = factory_text[m_plugin_name.c_str()](); //Polymorphism
233
} else if(m_class == "document") {
234
g_debug("DOCUMENT (%s)",m_plugin_name.c_str());
235
m_gloobus_interface = factory_document[m_plugin_name.c_str()](); //Polymorphism
236
} else if(m_class == "list") {
237
g_debug("LIST (%s)",m_plugin_name.c_str());
238
m_gloobus_interface = factory_list[m_plugin_name.c_str()](); //Polymorphism
239
} else if(m_class == "movie") {
240
g_debug("MOVIE (%s)",m_plugin_name.c_str());
241
m_gloobus_interface = factory_movie[m_plugin_name.c_str()](); //Polymorphism
242
} else if(m_class == "free") {
243
g_debug("FREE (%s)",m_plugin_name.c_str());
244
m_gloobus_interface = factory_free[m_plugin_name.c_str()](); //Polymorphism
55
m_plugin = PluginManager::get_plugin(get_filetype());
57
m_class = "default"; // TODO: remove this when iDefault will be made better
58
m_gloobus_interface = new iDefault();
248
m_gloobus_interface = new iDefault(); //Polymorphism
60
m_class = ""; // TODO: remove this when iDefault will be made better
61
m_gloobus_interface = m_plugin->create();
251
64
if(! m_gloobus_interface->set_filename(m_filename))
253
66
if(! m_gloobus_interface->load() )
256
//FIXME: Do it with signals :
257
//m_timeoutID = g_timeout_add (200, &Gloobus::check_fullscreen_trick,this);
261
71
// ============================= DESTROY PLUGIN ======================= //
262
72
void Gloobus::destroy_plugin()
264
74
g_debug("Destroying Plugin:");
266
g_source_remove(m_timeoutID);
270
75
if(m_gloobus_interface) {
271
m_gloobus_interface->end(); //Call a ending function before the destructor
272
//If we don't do this, thread functions
273
//calling virtual plugin function may crash
274
if(m_class == "image") {
275
factoryDestroy_image[m_plugin_name.c_str()](
276
(iImage*)m_gloobus_interface);
277
} else if(m_class == "music") {
278
factoryDestroy_music[m_plugin_name.c_str()](
279
(iMusic*)m_gloobus_interface);
280
} else if(m_class == "movie") {
281
factoryDestroy_movie[m_plugin_name.c_str()](
282
(iMovie*)m_gloobus_interface);
283
} else if(m_class == "text") {
284
factoryDestroy_text[m_plugin_name.c_str()](
285
(iText*)m_gloobus_interface);
286
} else if(m_class == "document") {
287
factoryDestroy_document[m_plugin_name.c_str()](
288
(iDocument*)m_gloobus_interface);
289
} else if(m_class == "list"){
290
factoryDestroy_list[m_plugin_name.c_str()](
291
(iList*)m_gloobus_interface);
292
} else if(m_class == "free"){
293
factoryDestroy_free[m_plugin_name.c_str()](
294
(iFree*)m_gloobus_interface);
295
} else if(m_class == "default"){
76
if(m_class == "default") { // TODO: remove this when iDefault will be made better
296
77
delete m_gloobus_interface;
79
m_plugin->destroy(m_gloobus_interface);
298
83
m_gloobus_interface = 0;
301
// ============================= GET WIDTH ======================= //
302
int Gloobus::get_width(void)
305
return m_gloobus_interface->get_width();
308
// ============================= GET HEIGHT ======================= //
309
int Gloobus::get_height(void)
311
return m_gloobus_interface->get_height();
314
87
// ============================= DRAW PLUGIN ======================= //
315
88
void Gloobus::draw_plugin(void)
566
gboolean Gloobus::check_fullscreen_trick(gpointer prInstance)
568
Gloobus * instance = (Gloobus*)prInstance;
569
if(instance->m_gloobus_interface->m_fullscreen_event)
571
instance->fullscreen( );
264
bool Gloobus::load_file( void ) {
266
g_object_unref(m_fileinfo);
268
g_object_unref(m_file);
270
m_file = g_file_new_for_path (m_filename.c_str () );
271
m_fileinfo = g_file_query_info(m_file, "*", G_FILE_QUERY_INFO_NONE,
275
g_error_new(g_quark_from_string ("Gloobus"), 3,
276
_("Error loading file info"));
576
void Gloobus::end_file_and_error( void ) {
283
void Gloobus::load_preview( void ) {
284
g_debug("Loading file: %s", m_filename.c_str());
287
g_error_free(m_error);
291
if(create_plugin()) {
292
m_gwindow->prepare_window();
293
g_signal_connect (m_gwindow->get_toolbar_pointer(),
294
"key-press-event", G_CALLBACK(key_press_cb), NULL);
296
// TODO: make here draw window only once fullscreen or nonfullscreen
299
if(m_gloobus_interface->can_fullscreen()) {
300
m_fullscreen = false;
303
gtk_window_unfullscreen (GTK_WINDOW(m_gwindow->get_window_pointer()));
304
//m_fullscreen = false;
308
m_error = m_gloobus_interface->get_error();
316
/* ****************************** GET SECTION ******************************* */
318
GloobusConfig* Gloobus::get_config( void ) {
320
m_config = new GloobusConfig;
321
m_config->load_config();
326
GFile* Gloobus::get_file( void ) {
330
GFileInfo* Gloobus::get_fileinfo( void ) {
334
string Gloobus::get_filetype( void ) {
335
string type = g_file_info_get_attribute_string (m_fileinfo,
336
"standard::content-type" );
337
type = type.substr(0,type.find(";"));
338
type = type.substr(0,type.find(","));
339
if(type == "x-directory/normal")
344
string Gloobus::get_filename( void ) {
348
int Gloobus::get_width(void) {
349
return m_gloobus_interface->get_width();
352
int Gloobus::get_height(void) {
353
return m_gloobus_interface->get_height();
356
/* ****************************** SHOW SECTION ****************************** */
358
void Gloobus::show_error( void ) {
359
if(m_gloobus_interface ) {
360
m_error = m_gloobus_interface->get_error();
361
//g_warning(m_error->message);
362
g_debug("Loading iDefault");
366
m_gloobus_interface = new iDefault();
367
m_gloobus_interface->set_filename(m_filename);
368
m_gloobus_interface->load();
370
m_gwindow->prepare_window();
371
g_signal_connect (m_gwindow->get_toolbar_pointer(),
372
"key-press-event", G_CALLBACK(key_press_cb), NULL);
376
//g_warning(m_error->message);
377
g_debug("Loading error dialog");
378
gtk_widget_destroy (GTK_WIDGET(m_gwindow->get_container_pointer()));
379
gtk_widget_destroy (GTK_WIDGET(m_gwindow->get_toolbar_pointer()));
381
m_gwindow->create_toolbar();
382
m_gwindow->create_container();
385
384 + SHADOW_WIDTH * 2,
386
128 + SHADOW_WIDTH * 2 /*+ BOTTOM_HEIGHT*/ + HEADER_HEIGHT);
387
m_gwindow->set_title(m_filename);
388
m_gwindow->add_common_buttons();
389
//GtkWidget * box = gtk_vbox_new(false, 0);
390
GtkWidget * icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_ERROR,
391
GTK_ICON_SIZE_DIALOG);
392
GtkWidget * label = gtk_label_new(m_error->message);
394
PangoAttrList *info_attrs = pango_attr_list_new();
395
pango_attr_list_insert(info_attrs,
396
pango_attr_foreground_new(53889,14927,253));
397
pango_attr_list_insert(info_attrs,
398
pango_attr_weight_new(PANGO_WEIGHT_BOLD));
399
pango_attr_list_insert(info_attrs, pango_attr_size_new(14*PANGO_SCALE));
400
gtk_widget_set_size_request(label, 256, 128);
401
gtk_label_set_attributes(GTK_LABEL(label), info_attrs);
402
gtk_label_set_line_wrap(GTK_LABEL(label), true);
403
gtk_misc_set_alignment(GTK_MISC(label), 0 , 0.5);
405
// GTK_ICON_SIZE_DIALOG is 40, for all themes?
406
// 128-40 /2 = 44 - place icon in the middle
407
gtk_fixed_put(GTK_FIXED(m_gwindow->get_container_pointer()),
408
icon, SHADOW_WIDTH+44, HEADER_HEIGHT + SHADOW_WIDTH + 44);
409
gtk_fixed_put(GTK_FIXED(m_gwindow->get_container_pointer()),
410
label, SHADOW_WIDTH+128, HEADER_HEIGHT + SHADOW_WIDTH);
411
gtk_widget_show_all(icon);
412
gtk_widget_show_all(label);
413
m_gwindow->show_all();
417
void Gloobus::show_help ( )
421
" gloobus-preview [%s...] [URI]\n\n",
422
_("Usage"), _("OPTION") );
426
"If URI is not provided Gloobus-Preview checks clipboard "
429
printf("%s:\n", _("Help options") );
430
printf(" -h, --help %s\n",
431
_("Show help options") );
433
printf("%s:\n", _("Application options") );
434
printf(" -d, --debug %s\n",
435
_("Show debug messages") );
436
printf(" --show-supported-filetypes %s\n",
437
_("Show supported filetypes") );
442
void Gloobus::show_preview(char * target)
445
gloobusWin * win = new gloobusWin();
446
win->create_window( DEFAULT_WIDTH, DEFAULT_HEIGHT );
449
g_signal_connect (win->get_window_pointer(), "key-press-event",
450
G_CALLBACK(key_press_cb), NULL);
452
win->create_toolbar();
453
g_signal_connect (win->get_toolbar_pointer(),"key-press-event",
454
G_CALLBACK(key_press_cb), NULL);
459
// check relative path:
460
if (filename.c_str()[0] != '/') {
461
filename = "./" + filename;
464
// strip final slash:
465
if (filename.c_str()[filename.size()-1] == '/') {
466
filename = filename.substr(0,filename.size()-1);
469
g_debug("Getting file from clipboard");
470
GtkClipboard *clip = gtk_clipboard_get ( GDK_SELECTION_CLIPBOARD );
471
gchar **uri = gtk_clipboard_wait_for_uris ( clip );
473
m_error = g_error_new(g_quark_from_string ("Gloobus"), 1,
474
_("There is no file in clipboard"));
476
filename = g_filename_from_uri(uri[0], NULL, NULL);
479
init( filename , win );
480
load_folder_filenames();
482
g_debug("Filename: %s", filename.c_str());
483
if( !search_actual_filename()) {
484
m_error = g_error_new(g_quark_from_string ("Gloobus"), 2,
485
_("File not found"));
578
g_error_free(m_error);
579
m_error = m_gloobus_interface->get_error();
582
gtk_widget_destroy (GTK_WIDGET(m_gwindow->get_container_pointer()));
583
gtk_widget_destroy (GTK_WIDGET(m_gwindow->get_toolbar_pointer()));
585
m_gwindow->create_toolbar();
586
m_gwindow->create_container();
587
g_signal_connect (m_gwindow->get_toolbar_pointer(),"key-press-event", //And this one, catchs key events
588
G_CALLBACK(key_press), NULL);
494
destroy_plugin(); //Destroy current plugin // TODO: do we really need this?
495
end(); //Unload All plugins before leave // TODO: do we really need this?
498
void Gloobus::show_supported_filetypes ( )
500
PluginManager::load_plugins ();
501
PluginManager::show_supported_filetypes();
502
PluginManager::unload_plugins();