2
* Copyright 2008 Michael Pfeuti <m_pfeuti@students.unibe.ch>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Library General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
#include <gdk/gdkkeysyms.h>
32
#include <gio/gdesktopappinfo.h>
34
#include <libxfcegui4/libxfcegui4.h>
35
#include <libxfce4panel/libxfce4panel.h>
37
#include "linelight.h"
39
#include "linelight-ico.h"
41
static LineLightData *linelight = NULL;
42
static GThread* current_search_thread;
44
static void plugin_create(XfcePanelPlugin *plugin);
45
static void showProperties_cb(XfcePanelPlugin *plugin, gpointer userdata);
46
static gboolean tree_mouse_selection (GtkWidget *widget, GdkEventButton *event, GtkWidget *tree);
47
static gboolean esc_event (GtkWidget *w, GdkEventKey *event, GtkWidget *entry);
48
static void start_search(GtkEditable *entry,char* user_data);
49
static void open_search_window_cb(GtkButton *button, XfcePanelPlugin* win);
50
static gboolean tree_selection (GtkWidget *widget, GdkEventKey *event, GtkWidget *tree);
51
static void cell_renderer (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data);
52
static gboolean delete_event(GtkWidget *w, GdkEvent* event, gpointer user_data);
58
//main window which takes text to search for and displays the result
59
static GtkWidget* create_windows_content(GtkListStore *list)
61
GtkWidget *hbox = gtk_vbox_new(FALSE, 5);
63
GtkWidget *tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list));
64
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
65
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree), FALSE);
69
GtkCellRenderer *icon_renderer = gtk_cell_renderer_pixbuf_new();
70
GtkTreeViewColumn *icon_column = gtk_tree_view_column_new_with_attributes("Icon", icon_renderer,"pixbuf", ICON_COL,NULL);
71
//gtk_tree_view_column_set_resizable(icon_column, FALSE);
72
//gtk_tree_view_column_set_sizing(icon_column,GTK_TREE_VIEW_COLUMN_AUTOSIZE);
73
gtk_tree_view_append_column(GTK_TREE_VIEW (tree), icon_column);
76
GtkCellRenderer *text_renderer = gtk_cell_renderer_text_new ();
77
/* g_object_set(renderer,"size-set",TRUE,NULL);
78
g_object_set(renderer,"size-points",9.0,NULL);
79
g_object_set(renderer,"height", 0,NULL);
80
GtkTreeViewColumn *text_column = gtk_tree_view_column_new();
81
gtk_tree_view_column_set_title(text_column,"LineLight");
82
gtk_tree_view_column_pack_start(text_column, text_renderer, FALSE);
84
GtkTreeViewColumn *text_column = gtk_tree_view_column_new_with_attributes("Text", text_renderer,"text", TEXT_COL,NULL);
85
gtk_tree_view_column_set_resizable(text_column, FALSE);
86
gtk_tree_view_column_set_sizing(text_column,GTK_TREE_VIEW_COLUMN_AUTOSIZE);
87
gtk_tree_view_column_set_cell_data_func(text_column, text_renderer, cell_renderer, NULL, NULL);
88
gtk_tree_view_append_column(GTK_TREE_VIEW (tree), text_column);
89
gtk_container_add(GTK_CONTAINER(hbox), tree);
91
GtkWidget *entry = gtk_entry_new();
93
gtk_container_add(GTK_CONTAINER(hbox), entry);
95
g_signal_connect(tree,"key-release-event", G_CALLBACK(tree_selection),entry);
96
g_signal_connect(tree,"button-press-event", G_CALLBACK(tree_mouse_selection), entry);
97
g_signal_connect(entry,"key-release-event", G_CALLBACK(esc_event),NULL);
98
g_signal_connect(entry, "changed", G_CALLBACK(start_search), NULL);
100
linelight->text_field = entry;
105
static void move_action_cb(GtkWidget *w, GtkRequisition *g, XfcePanelPlugin* plugin)
107
switch (linelight->grow_corner)
109
case TOP_RIGHT_CORNER:
110
gtk_window_move(GTK_WINDOW(w), linelight->x - g->width, linelight->y);
112
case BOTTOM_LEFT_CORNER:
113
gtk_window_move(GTK_WINDOW(w), linelight->x, linelight->y - g->height);
115
case BOTTOM_RIGHT_CORNER:
116
gtk_window_move(GTK_WINDOW(w), linelight->x - g->width, linelight->y - g->height);
118
case TOP_LEFT_CORNER:
119
gtk_window_move(GTK_WINDOW(w), linelight->x, linelight->y);
124
static void cell_renderer(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
129
gtk_tree_model_get(model, iter, ICON_COL, &buf, TEXT_COL, &path, -1);
134
name = strrchr(path, '/');
136
if (name == NULL) //" " or SECTION Name
138
//indicate # of search results
140
for (i = 0;i<SECTION_COUNT; i++)
142
if (strcmp(path,sectionNames[i]) == 0)
143
count = linelight->all_found_results[i];
147
char entry[strlen(path) + 100]; // 100 chars for indicating how many results are found
148
sprintf(entry, "%s (%i)", path, count);
149
g_object_set(cell,"text", entry,NULL);
153
g_object_set(cell,"text", path,NULL);
156
else if (strstr(name,".desktop") != NULL) //Application names based on .desktop files
158
XfceDesktopEntry *application = xfce_desktop_entry_new(path,categories,3);
159
if (XFCE_IS_DESKTOP_ENTRY(application))
162
xfce_desktop_entry_get_string(application, "Name", TRUE, &app_name);
163
g_object_unref(application);
164
g_object_set(cell,"text", app_name,NULL);
170
g_object_set(cell,"text", ++name,NULL);
175
static gboolean panel_resize_cb(XfcePanelPlugin *plugin, gint new_size, gpointer but)
177
GtkWidget *img = gtk_image_new();
178
GdkPixbuf *pb = gdk_pixbuf_new_from_inline(-1, linelightico, FALSE, NULL);
179
int size = new_size - 5;
180
GdkPixbuf *pb_scaled = gdk_pixbuf_scale_simple(pb,size,size, GDK_INTERP_HYPER);
181
gtk_image_set_from_pixbuf(GTK_IMAGE(img), pb_scaled);
182
g_object_unref(G_OBJECT(pb));
183
g_object_unref(G_OBJECT(pb_scaled));
184
gtk_button_set_image(GTK_BUTTON(but), GTK_WIDGET(img));
185
gtk_widget_set_size_request(GTK_WIDGET(but), new_size, new_size);
193
void* search(void *arg)
196
FILE *search_process;
197
char line[MAX_PATH_LENGTH];
199
command = (char*) arg;
200
search_process = popen(command, "r");
202
if (search_process == NULL)
204
xfce_err("locate clould not be executed!");
209
linelight_clear_list(linelight);
212
while (NULL!=fgets(line, MAX_PATH_LENGTH, search_process) && g_thread_self() == current_search_thread)
215
linelight_add_search_result(linelight, line);
220
pclose(search_process);
226
static void start_search(GtkEditable *entry, char *user_data)
228
const char *search_string;
231
search_string = gtk_entry_get_text(GTK_ENTRY(entry));
233
if (strlen(search_string) < linelight->min_char_for_search)
235
current_search_thread = NULL;
236
linelight_clear_list(linelight);
239
command = malloc(sizeof(char) *(20 + strlen(search_string)));
240
//strcpy(command, "locate -b \"");
241
strcpy(command, "locate -b ");
242
strcat(command, gtk_entry_get_text(GTK_ENTRY(entry)));
243
//strcat(command, "\"");
245
current_search_thread = g_thread_create(search, (void *)command, FALSE, NULL);
249
* Mouse, Keyboads and Button Event Methods
252
static void executeFile(char* path)
257
GDesktopAppInfo *desktop_app;
258
GList *fileList = NULL;
260
file = g_file_new_for_path (path);
264
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
267
g_object_unref (file);
271
if (strstr(path,".desktop") != 0)
273
desktop_app = g_desktop_app_info_new_from_filename (path);
274
if (desktop_app != NULL)
276
g_app_info_launch (G_APP_INFO (desktop_app), NULL, NULL, NULL);
277
g_object_unref (desktop_app);
280
else if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
282
char command[strlen(path) + 10];
283
strcpy(command, "thunar \"");
284
strcat(command, path);
285
strcat(command,"\"");
290
fileList = g_list_append (fileList, file);
292
app = g_app_info_get_default_for_type (g_file_info_get_content_type (info), FALSE);
294
g_app_info_launch (app, fileList, NULL, NULL);
297
g_list_free(fileList);
299
g_object_unref (info);
300
g_object_unref (file);
303
void* show_all_search_results(void* arg)
305
const char *search_string;
306
FILE *search_process;
307
search_string = gtk_entry_get_text(GTK_ENTRY(linelight->text_field));
308
char command[20 + strlen(search_string)], line[MAX_PATH_LENGTH], link_command[MAX_PATH_LENGTH * 2];
309
//strcpy(command, "locate -b \"");
310
strcpy(command, "locate -b ");
311
strcat(command, gtk_entry_get_text(GTK_ENTRY(linelight->text_field)));
312
//strcat(command, "\"");
314
search_process = popen(command, "r");
316
if (search_process == NULL)
318
xfce_err("locate clould not be executed!");
321
system("rm -r /tmp/xfce4-linelight/");
322
system("mkdir /tmp/xfce4-linelight/");
323
while (NULL!=fgets(line, MAX_PATH_LENGTH, search_process))
325
//remove /n at the end
326
if (strlen(line) != 0 && line[strlen(line)-1] == '\n')
327
line[strlen(line)-1] = '\0' ;
329
sprintf(link_command, "ln -s \"%s\" /tmp/xfce4-linelight/", line);
330
system(link_command);
333
pclose(search_process);
334
system("thunar /tmp/xfce4-linelight/");
338
//TODO: remove dublicated code
339
void* show_all_search_results_from_section(void* sec)
341
const char *search_string;
342
FILE *search_process;
344
search_string = gtk_entry_get_text(GTK_ENTRY(linelight->text_field));
345
char command[20 + strlen(search_string)], line[MAX_PATH_LENGTH], link_command[MAX_PATH_LENGTH * 2];
346
//strcpy(command, "locate -b \"");
347
strcpy(command, "locate -b ");
348
strcat(command, gtk_entry_get_text(GTK_ENTRY(linelight->text_field)));
349
//strcat(command, "\"");
351
search_process = popen(command, "r");
353
if (search_process == NULL)
355
xfce_err("locate clould not be executed!");
359
system("rm -r /tmp/xfce4-linelight/");
360
system("mkdir /tmp/xfce4-linelight/");
361
while (NULL!=fgets(line, MAX_PATH_LENGTH, search_process))
363
section = linelight_get_result_section(linelight,line);
364
if (section == *((int*)sec))
366
//remove /n at the end
367
// if (strlen(line) != 0 && line[strlen(line)-1] == '\n')
368
// line[strlen(line)-1] = '\0' ;
370
sprintf(link_command, "ln -s \"%s\" /tmp/xfce4-linelight/", line);
371
system(link_command);
375
pclose(search_process);
376
system("thunar /tmp/xfce4-linelight/");
381
void executeAction(char *text)
385
// more... was selected
386
if (strcmp(text,"more...") == 0)
388
g_thread_create(show_all_search_results, NULL, FALSE, NULL);
391
//A section was selected
392
for (i = 0;i<SECTION_COUNT; i++)
394
if (strstr(text,sectionNames[i]) != NULL)
396
int *section = malloc(sizeof(int));
398
g_thread_create(show_all_search_results_from_section, (void*)section, FALSE, NULL);
402
//a path was selected
406
static gboolean tree_mouse_selection (GtkWidget *tree, GdkEventButton *event, GtkWidget *entry)
408
if (event->type == GDK_2BUTTON_PRESS)
410
GtkTreeSelection *selection;
415
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
417
if (gtk_tree_selection_get_selected (selection, &model, &iter))
419
gtk_tree_model_get(model, &iter, TEXT_COL, &path, -1);
429
static gboolean tree_selection(GtkWidget *tree, GdkEventKey *event, GtkWidget *entry)
431
if (event->keyval == GDK_Escape || event->keyval == GDK_F4)
433
linelight_toggle_show_hide(linelight);
435
else if (event->keyval == GDK_Return)
437
GtkTreeSelection *selection;
442
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));;
444
if (gtk_tree_selection_get_selected (selection, &model, &iter))
446
gtk_tree_model_get(model, &iter, TEXT_COL, &path, -1);
452
else if (event->keyval != GDK_Up && event->keyval != GDK_Down)
454
gtk_widget_grab_focus(entry);
455
gtk_entry_append_text(GTK_ENTRY(entry),event->string);
456
const char *text = gtk_entry_get_text(GTK_ENTRY(entry));
457
gtk_editable_select_region(GTK_EDITABLE(entry), strlen(text),strlen(text));
462
//callback for the panel button (creates or destroys the main window)
463
static void open_search_window_cb(GtkButton *button, XfcePanelPlugin* plugin)
465
linelight_toggle_show_hide(linelight);
468
static gboolean esc_event(GtkWidget *w, GdkEventKey *event, GtkWidget *entry)
470
if (event->keyval == GDK_Escape || event->keyval == GDK_F4)
472
linelight_toggle_show_hide(linelight);
478
static gboolean delete_event(GtkWidget *w, GdkEvent* event, gpointer user_data)
480
linelight_toggle_show_hide(linelight);
488
static void show_about_cb(XfcePanelPlugin *plugin, gpointer userdata)
491
XfceAboutInfo *info = xfce_about_info_new("xfce4-linelight-plugin", VERSION, _("A Spotlight-like frontend for locate search."), XFCE_COPYRIGHT_TEXT("2008", "Michael Pfeuti"), XFCE_LICENSE_GPL);
493
xfce_about_info_set_homepage(info,"http://www.ganymede.ch");
495
dialog = xfce_about_dialog_new_with_values(NULL, info, NULL);
496
g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_destroy),NULL);
497
gtk_window_set_title(GTK_WINDOW(dialog), "xfce4-linelight");
498
gtk_dialog_run(GTK_DIALOG(dialog));
500
xfce_about_info_free(info);
504
* Persistance and Clean-Up
507
static void load_data(XfcePanelPlugin *plugin, LineLightData *data)
512
char sec_enable[] = "section_enabled_#";
514
if (!(file = xfce_panel_plugin_lookup_rc_file(plugin)))
517
rc = xfce_rc_simple_open(file,TRUE);
523
data->max_search_results = xfce_rc_read_int_entry(rc,"max_search_results", 5);
524
data->grow_corner = xfce_rc_read_int_entry(rc,"grow_corner",TOP_LEFT_CORNER);
525
data->decorated = xfce_rc_read_int_entry(rc,"decorated", TRUE);
526
data->x = xfce_rc_read_int_entry(rc,"coord_x", gdk_screen_width()/2);
527
data->y = xfce_rc_read_int_entry(rc,"coord_y", gdk_screen_height()/2);
528
data->min_char_for_search = xfce_rc_read_int_entry(rc,"min_char_for_search",2);
529
for(i = 0;i<SECTION_COUNT;i++)
531
sprintf(sec_enable, "section_enabled_%i", i);
532
data->section_enabled[i] = xfce_rc_read_int_entry(rc,sec_enable, TRUE);
538
static void save_data_cb(XfcePanelPlugin *plugin, gpointer userdata)
543
char sec_enable[] = "section_enabled_#";
545
if (!(file = xfce_panel_plugin_save_location(plugin, TRUE)))
548
rc = xfce_rc_simple_open(file,FALSE);
554
xfce_rc_write_int_entry(rc,"max_search_results", linelight->max_search_results);
555
xfce_rc_write_int_entry(rc,"grow_corner", (int) linelight->grow_corner);
556
xfce_rc_write_int_entry(rc,"decorated", linelight->decorated);
557
xfce_rc_write_int_entry(rc,"coord_x", linelight->x);
558
xfce_rc_write_int_entry(rc,"coord_y", linelight->y);
559
xfce_rc_write_int_entry(rc,"min_char_for_search",linelight->min_char_for_search);
560
for(i = 0;i<SECTION_COUNT;i++)
562
sprintf(sec_enable, "section_enabled_%i", i);
563
xfce_rc_write_int_entry(rc,sec_enable, linelight->section_enabled[i]);
569
static void clean_up_cb(XfcePanelPlugin *plugin, gpointer userdata)
571
save_data_cb(plugin, userdata);
572
linelight_free(linelight);
573
system("rm -r /tmp/xfce4-linelight/");
574
gdk_threads_leave ();
578
* Properties Frame and Callback Methods
581
static void set_max_results_value_cb(GtkWidget *spinner, gpointer userdata)
583
linelight->max_search_results = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner));
586
static void min_char_for_search_value_cb(GtkWidget *spinner, gpointer userdata)
588
linelight->min_char_for_search = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner));
591
static void toggle_window_decoration_cb(GtkWidget *but, gpointer userdata)
593
linelight->decorated = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
594
gtk_window_set_decorated(GTK_WINDOW (linelight->text_window), linelight->decorated);
597
static void section_selection_cb(GtkWidget *but, gpointer userdata)
599
const char *section = gtk_button_get_label(GTK_BUTTON(but));
600
if (strcmp("Music", section) == 0)
601
linelight->section_enabled[MUSIC_SECTION] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
602
if (strcmp("Videos", section) == 0)
603
linelight->section_enabled[VIDEO_SECTION] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
604
if (strcmp("Pictures", section) == 0)
605
linelight->section_enabled[PICTURES_SECTION] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
606
if (strcmp("Applications", section) == 0)
607
linelight->section_enabled[BIN_SECTION] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
608
if (strcmp("Files", section) == 0)
609
linelight->section_enabled[FILES_SECTION] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
610
if (strcmp("Folders", section) == 0)
611
linelight->section_enabled[FOLDER_SECTION] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
612
//if(strcmp("Web", section) == 0)
613
// linelight->section_enabled[WEB_SECTION] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
616
static void grow_corner_selection_cb(GtkWidget *but, gpointer userdata)
618
const char *section = gtk_button_get_label(GTK_BUTTON(but));
619
if (strcmp("Top Right", section) == 0)
620
linelight->grow_corner = TOP_RIGHT_CORNER;
621
if (strcmp("Top Left", section) == 0)
622
linelight->grow_corner = TOP_LEFT_CORNER;
623
if (strcmp("Bottom Right", section) == 0)
624
linelight->grow_corner = BOTTOM_RIGHT_CORNER;
625
if (strcmp("Bottom Left", section) == 0)
626
linelight->grow_corner = BOTTOM_LEFT_CORNER;
629
static void showProperties_cb(XfcePanelPlugin *plugin, gpointer userdata)
631
linelight_update_coordinates(linelight);
632
gtk_widget_hide(linelight->text_window);
633
xfce_panel_plugin_block_menu(plugin);
635
GtkWidget *dialog = gtk_dialog_new_with_buttons("Properties", GTK_WINDOW(plugin), GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
637
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
638
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
640
GtkWidget *table = gtk_table_new(3,4,FALSE);
641
gtk_table_set_col_spacing(GTK_TABLE(table),0,5);
643
//left side of the dialog
644
GtkWidget *section_frame = gtk_frame_new("Section Selection");
645
GtkWidget *section_selection = gtk_vbox_new(FALSE,5);
647
GtkWidget *box = gtk_check_button_new_with_label("Music");
648
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box),linelight->section_enabled[MUSIC_SECTION]);
649
g_signal_connect(box,"toggled",G_CALLBACK(section_selection_cb),NULL);
650
gtk_container_add(GTK_CONTAINER(section_selection), box);
652
box = gtk_check_button_new_with_label("Videos");
653
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box),linelight->section_enabled[VIDEO_SECTION]);
654
g_signal_connect(box,"toggled",G_CALLBACK(section_selection_cb),NULL);
655
gtk_container_add(GTK_CONTAINER(section_selection), box);
657
box = gtk_check_button_new_with_label("Pictures");
658
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box),linelight->section_enabled[PICTURES_SECTION]);
659
g_signal_connect(box,"toggled",G_CALLBACK(section_selection_cb),NULL);
660
gtk_container_add(GTK_CONTAINER(section_selection), box);
662
//box = gtk_check_button_new_with_label("Web");
663
//gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box),linelight->section_enabled[WEB_SECTION]);
664
//g_signal_connect(box,"toggled",G_CALLBACK(section_selection_cb),NULL);
665
//gtk_container_add(GTK_CONTAINER(section_selection), box);
667
box = gtk_check_button_new_with_label("Applications");
668
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box),linelight->section_enabled[BIN_SECTION]);
669
g_signal_connect(box,"toggled",G_CALLBACK(section_selection_cb),NULL);
670
gtk_container_add(GTK_CONTAINER(section_selection), box);
672
box = gtk_check_button_new_with_label("Files");
673
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box),linelight->section_enabled[FILES_SECTION]);
674
g_signal_connect(box,"toggled",G_CALLBACK(section_selection_cb),NULL);
675
gtk_container_add(GTK_CONTAINER(section_selection), box);
677
box = gtk_check_button_new_with_label("Folders");
678
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(box),linelight->section_enabled[FOLDER_SECTION]);
679
g_signal_connect(box,"toggled",G_CALLBACK(section_selection_cb),NULL);
680
gtk_container_add(GTK_CONTAINER(section_selection), box);
682
gtk_container_add(GTK_CONTAINER(section_frame), section_selection);
683
gtk_table_attach(GTK_TABLE(table), section_frame,0,1,0,4,GTK_FILL,GTK_FILL,0,0);
685
//right side of the dialog
686
GtkWidget *decoration_label = gtk_label_new("Show Window Decoration: ");
687
gtk_misc_set_alignment(GTK_MISC(decoration_label), 0, 0.5);
688
gtk_table_attach(GTK_TABLE(table), decoration_label,1,2,0,1,GTK_FILL,GTK_FILL,0,0);
689
GtkWidget *decoration_checkbox = gtk_check_button_new();
690
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(decoration_checkbox), gtk_window_get_decorated(GTK_WINDOW(linelight->text_window)));
691
g_signal_connect(decoration_checkbox,"toggled",G_CALLBACK(toggle_window_decoration_cb),NULL);
692
gtk_table_attach(GTK_TABLE(table), decoration_checkbox,2,3,0,1,GTK_FILL,GTK_FILL,0,0);
694
GtkWidget *spinner_label = gtk_label_new("Max Results Per Section: ");
695
gtk_misc_set_alignment(GTK_MISC(spinner_label), 0, 0.5);
696
gtk_table_attach(GTK_TABLE(table), spinner_label,1,2,1,2,GTK_FILL,GTK_FILL,0,0);
697
GtkWidget *spinner = gtk_spin_button_new_with_range(1,20,1.0);
698
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner), (double) linelight->max_search_results);
699
g_signal_connect(spinner,"value-changed",G_CALLBACK(set_max_results_value_cb),NULL);
700
gtk_table_attach(GTK_TABLE(table), spinner,2,3,1,2,GTK_FILL,GTK_FILL,0,0);
702
spinner_label = gtk_label_new("Min Character to Search: ");
703
gtk_misc_set_alignment(GTK_MISC(spinner_label), 0, 0.5);
704
gtk_table_attach(GTK_TABLE(table), spinner_label,1,2,2,3,GTK_FILL,GTK_FILL,0,0);
705
spinner = gtk_spin_button_new_with_range(1,20,1.0);
706
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner), (double) linelight->min_char_for_search);
707
g_signal_connect(spinner,"value-changed",G_CALLBACK(min_char_for_search_value_cb),NULL);
708
gtk_table_attach(GTK_TABLE(table), spinner,2,3,2,3,GTK_FILL,GTK_FILL,0,0);
710
GtkWidget *corner_frame = gtk_frame_new("Fix Corner When Resizing");
711
GtkWidget *corner_selection = gtk_vbox_new(FALSE,5);
713
GtkWidget *radio = gtk_radio_button_new_with_label(NULL,"Top Left");
714
g_signal_connect(radio,"toggled",G_CALLBACK(grow_corner_selection_cb),NULL);
715
if (linelight->grow_corner == TOP_LEFT_CORNER)
716
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
717
gtk_container_add(GTK_CONTAINER(corner_selection), radio);
719
radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio),"Top Right");
720
g_signal_connect(radio,"toggled",G_CALLBACK(grow_corner_selection_cb),NULL);
721
if (linelight->grow_corner == TOP_RIGHT_CORNER)
722
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
723
gtk_container_add(GTK_CONTAINER(corner_selection), radio);
725
radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio),"Bottom Left");
726
g_signal_connect(radio,"toggled",G_CALLBACK(grow_corner_selection_cb),NULL);
727
if (linelight->grow_corner == BOTTOM_LEFT_CORNER)
728
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
729
gtk_container_add(GTK_CONTAINER(corner_selection), radio);
731
radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio),"Bottom Right");
732
g_signal_connect(radio,"toggled",G_CALLBACK(grow_corner_selection_cb),NULL);
733
if (linelight->grow_corner == BOTTOM_RIGHT_CORNER)
734
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
735
gtk_container_add(GTK_CONTAINER(corner_selection), radio);
737
gtk_container_add(GTK_CONTAINER(corner_frame), corner_selection);
738
gtk_table_attach(GTK_TABLE(table), corner_frame,1,3,3,4,GTK_FILL,GTK_FILL,0,0);
741
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
742
gtk_widget_show_all(dialog);
743
gtk_window_set_resizable(GTK_WINDOW(dialog),FALSE);
744
gtk_dialog_run(GTK_DIALOG(dialog));
746
linelight_clear_list(linelight);
747
xfce_panel_plugin_unblock_menu(plugin);
751
* APPLICATION START METHODS
755
int main (int argc, char *argv[])
758
g_thread_init (NULL);
762
gtk_init (&argc, &argv);
766
GtkWidget *text_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
767
gtk_window_set_resizable(GTK_WINDOW(text_window),FALSE);
768
g_signal_connect(GTK_WIDGET(text_window), "size-request", G_CALLBACK(move_action_cb), NULL);
769
GtkListStore *list = gtk_list_store_new(NUM_COLUMS,GDK_TYPE_PIXBUF, G_TYPE_STRING);
770
//gtk_window_set_decorated(GTK_WINDOW (text_window), FALSE);
771
//gtk_window_set_accept_focus(GTK_WINDOW(text_window), TRUE);
772
//g_object_set(text_window, "has-toplevel-focus",TRUE,NULL);
773
//g_object_set(text_window, "focus-on-map",TRUE,NULL);
774
linelight = linelight_new(text_window, list);
775
gtk_container_add(GTK_CONTAINER(text_window), create_windows_content(list));
776
showProperties_cb(NULL,NULL);
778
gtk_widget_show_all(text_window);
779
gtk_widget_grab_focus(text_window);
783
gdk_threads_leave ();
787
// callback for xfce panel (executed on plugin addition)
788
static void plugin_create(XfcePanelPlugin *plugin)
791
g_thread_init (NULL);
795
xfce_panel_plugin_menu_show_configure(plugin);
796
xfce_panel_plugin_menu_show_about(plugin);
798
GtkWidget *button = xfce_create_panel_button();
799
gtk_container_add(GTK_CONTAINER(plugin), button);
800
xfce_panel_plugin_add_action_widget(plugin, button);
801
panel_resize_cb(plugin,xfce_panel_plugin_get_size(plugin), button);
802
gtk_widget_show_all(button);
804
g_signal_connect(plugin, "free-data", G_CALLBACK(clean_up_cb), NULL);
805
g_signal_connect(plugin, "about", G_CALLBACK(show_about_cb), NULL);
806
g_signal_connect(plugin, "configure-plugin", G_CALLBACK(showProperties_cb), NULL);
807
g_signal_connect(plugin, "save", G_CALLBACK(save_data_cb), NULL);
808
g_signal_connect(button, "clicked", G_CALLBACK(open_search_window_cb), button);
809
g_signal_connect (plugin, "size-changed", G_CALLBACK(panel_resize_cb), button);
810
gtk_tooltips_set_tip(gtk_tooltips_new(), button, "Linelight", NULL);
813
GtkWidget *text_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
814
gtk_window_set_resizable(GTK_WINDOW(text_window),FALSE);
815
gtk_window_set_deletable(GTK_WINDOW(text_window),FALSE);
816
gtk_window_set_keep_above(GTK_WINDOW(text_window),TRUE);
817
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(text_window),TRUE);
818
g_signal_connect(GTK_WIDGET(text_window), "size-request", G_CALLBACK(move_action_cb), plugin);
819
GtkListStore *list = gtk_list_store_new(NUM_COLUMS,GDK_TYPE_PIXBUF, G_TYPE_STRING);
820
linelight = linelight_new(text_window, list);
821
gtk_container_add(GTK_CONTAINER(text_window), create_windows_content(list));
822
g_signal_connect(text_window, "delete-event", G_CALLBACK(delete_event), NULL);
824
load_data(plugin,linelight);
825
linelight_clear_list(linelight);
826
if(linelight->decorated)
827
gtk_window_set_decorated(GTK_WINDOW (text_window), TRUE);
829
gtk_window_set_decorated(GTK_WINDOW (text_window), FALSE);
834
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(plugin_create);