~ubuntu-branches/ubuntu/quantal/xfce4-linelight-plugin/quantal

« back to all changes in this revision

Viewing changes to .pc/01_port-to-xfcerc.patch/panel-plugin/main.c

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2012-05-19 13:23:38 UTC
  • Revision ID: package-import@ubuntu.com-20120519132338-m1v7icu0izxejnw1
Tags: 0.1.7-2ubuntu1
* debian/patches:
  - 01_port-to-xfcerc.patch: added, port to libxfce4util6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright 2008 Michael Pfeuti <m_pfeuti@students.unibe.ch>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include <stdlib.h>
 
20
#include <string.h>
 
21
#include <stdlib.h>
 
22
#include <glib.h>
 
23
#include <signal.h>
 
24
#include <unistd.h>
 
25
 
 
26
#include <gtk/gtk.h>
 
27
 
 
28
#include <gdk/gdkkeysyms.h>
 
29
#include <gdk/gdk.h>
 
30
 
 
31
#include <gio/gio.h>
 
32
#include <gio/gdesktopappinfo.h>
 
33
 
 
34
#include <libxfcegui4/libxfcegui4.h>
 
35
#include <libxfce4panel/libxfce4panel.h>
 
36
 
 
37
#include "linelight.h"
 
38
#include "defines.h"
 
39
#include "linelight-ico.h"
 
40
 
 
41
static LineLightData *linelight = NULL;
 
42
static GThread* current_search_thread;
 
43
 
 
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);
 
53
 
 
54
/*
 
55
 *  GUI Handling
 
56
 */
 
57
 
 
58
//main window which takes text to search for and displays the result
 
59
static GtkWidget* create_windows_content(GtkListStore *list)
 
60
{
 
61
    GtkWidget *hbox = gtk_vbox_new(FALSE, 5);
 
62
 
 
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);
 
66
 
 
67
 
 
68
    //ICON col
 
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);
 
74
 
 
75
    //Text col
 
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);
 
83
    */
 
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);
 
90
 
 
91
    GtkWidget *entry = gtk_entry_new();
 
92
 
 
93
    gtk_container_add(GTK_CONTAINER(hbox), entry);
 
94
 
 
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);
 
99
 
 
100
    linelight->text_field = entry;
 
101
 
 
102
    return hbox;
 
103
}
 
104
 
 
105
static void move_action_cb(GtkWidget *w, GtkRequisition *g, XfcePanelPlugin* plugin)
 
106
{
 
107
    switch (linelight->grow_corner)
 
108
    {
 
109
    case TOP_RIGHT_CORNER:
 
110
        gtk_window_move(GTK_WINDOW(w), linelight->x - g->width, linelight->y);
 
111
        break;
 
112
    case BOTTOM_LEFT_CORNER:
 
113
        gtk_window_move(GTK_WINDOW(w), linelight->x, linelight->y - g->height);
 
114
        break;
 
115
    case BOTTOM_RIGHT_CORNER:
 
116
        gtk_window_move(GTK_WINDOW(w), linelight->x - g->width, linelight->y - g->height);
 
117
        break;
 
118
    case TOP_LEFT_CORNER:
 
119
        gtk_window_move(GTK_WINDOW(w), linelight->x, linelight->y);
 
120
        break;
 
121
    }
 
122
}
 
123
 
 
124
static void cell_renderer(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 
125
{
 
126
    char *path, *name;
 
127
    GdkPixbuf *buf;
 
128
 
 
129
    gtk_tree_model_get(model, iter, ICON_COL, &buf, TEXT_COL, &path, -1);
 
130
 
 
131
    if (path == NULL)
 
132
       return;
 
133
 
 
134
    name = strrchr(path, '/');
 
135
 
 
136
    if (name == NULL) //" " or SECTION Name
 
137
    {
 
138
        //indicate # of search results
 
139
        int i, count = 0;
 
140
        for (i =  0;i<SECTION_COUNT; i++)
 
141
        {
 
142
            if (strcmp(path,sectionNames[i]) == 0)
 
143
                count = linelight->all_found_results[i];
 
144
        }
 
145
        if (count != 0)
 
146
        {
 
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);
 
150
        }
 
151
        else
 
152
        {
 
153
            g_object_set(cell,"text", path,NULL);
 
154
        }
 
155
    }
 
156
    else if (strstr(name,".desktop") != NULL) //Application names based on .desktop files
 
157
    {
 
158
        XfceDesktopEntry *application = xfce_desktop_entry_new(path,categories,3);
 
159
        if (XFCE_IS_DESKTOP_ENTRY(application))
 
160
        {
 
161
            char* app_name;
 
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);
 
165
            free(app_name);
 
166
        }
 
167
    }
 
168
    else
 
169
    {
 
170
        g_object_set(cell,"text", ++name,NULL);
 
171
    }
 
172
    g_free(path);
 
173
}
 
174
 
 
175
static gboolean panel_resize_cb(XfcePanelPlugin *plugin, gint new_size, gpointer but)
 
176
{
 
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);
 
186
    return TRUE;
 
187
}
 
188
 
 
189
/*
 
190
 *  Search Handling
 
191
 */
 
192
 
 
193
void* search(void *arg)
 
194
{
 
195
    char *command;
 
196
    FILE *search_process;
 
197
    char line[MAX_PATH_LENGTH];
 
198
 
 
199
    command = (char*) arg;
 
200
    search_process = popen(command, "r");
 
201
 
 
202
    if (search_process == NULL)
 
203
    {
 
204
        xfce_err("locate clould not be executed!");
 
205
        return NULL;
 
206
    }
 
207
 
 
208
    gdk_threads_enter();
 
209
    linelight_clear_list(linelight);
 
210
    gdk_threads_leave();
 
211
 
 
212
    while (NULL!=fgets(line, MAX_PATH_LENGTH, search_process) && g_thread_self() == current_search_thread)
 
213
    {
 
214
        gdk_threads_enter();
 
215
        linelight_add_search_result(linelight, line);
 
216
        gdk_threads_leave();
 
217
 
 
218
    }
 
219
 
 
220
    pclose(search_process);
 
221
    free(command);
 
222
    g_thread_exit(NULL);
 
223
    return NULL;
 
224
}
 
225
 
 
226
static void start_search(GtkEditable *entry, char *user_data)
 
227
{
 
228
    const char *search_string;
 
229
    char *command;
 
230
 
 
231
    search_string = gtk_entry_get_text(GTK_ENTRY(entry));
 
232
 
 
233
    if (strlen(search_string) < linelight->min_char_for_search)
 
234
    {
 
235
        current_search_thread = NULL;
 
236
        linelight_clear_list(linelight);
 
237
        return;
 
238
    }
 
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, "\"");
 
244
 
 
245
    current_search_thread = g_thread_create(search, (void *)command, FALSE, NULL);
 
246
}
 
247
 
 
248
/*
 
249
 *  Mouse, Keyboads and Button Event Methods
 
250
 */
 
251
 
 
252
static void executeFile(char* path)
 
253
{
 
254
    GFile           *file;
 
255
    GFileInfo       *info;
 
256
    GAppInfo        *app;
 
257
    GDesktopAppInfo *desktop_app;
 
258
    GList           *fileList = NULL;
 
259
 
 
260
    file = g_file_new_for_path (path);
 
261
    if (file == NULL)
 
262
         return;
 
263
 
 
264
    info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
 
265
    if (info == NULL)
 
266
    {
 
267
        g_object_unref (file);
 
268
        return;
 
269
    }
 
270
 
 
271
    if (strstr(path,".desktop") != 0)
 
272
    {
 
273
        desktop_app = g_desktop_app_info_new_from_filename (path);
 
274
        if (desktop_app != NULL)
 
275
        {
 
276
            g_app_info_launch (G_APP_INFO (desktop_app), NULL, NULL, NULL);
 
277
            g_object_unref (desktop_app);
 
278
        }
 
279
    }
 
280
    else if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
 
281
    {
 
282
        char command[strlen(path) + 10];
 
283
        strcpy(command, "thunar \"");
 
284
        strcat(command, path);
 
285
        strcat(command,"\"");
 
286
        system(command);
 
287
    }
 
288
    else
 
289
    {
 
290
        fileList = g_list_append (fileList, file);
 
291
 
 
292
        app = g_app_info_get_default_for_type (g_file_info_get_content_type (info), FALSE);
 
293
 
 
294
        g_app_info_launch (app, fileList, NULL, NULL);
 
295
 
 
296
        g_object_unref(app);
 
297
        g_list_free(fileList);
 
298
    }
 
299
    g_object_unref (info);
 
300
    g_object_unref (file);
 
301
}
 
302
 
 
303
void* show_all_search_results(void* arg)
 
304
{
 
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, "\"");
 
313
 
 
314
    search_process = popen(command, "r");
 
315
 
 
316
    if (search_process == NULL)
 
317
    {
 
318
        xfce_err("locate clould not be executed!");
 
319
        return NULL;
 
320
    }
 
321
    system("rm -r /tmp/xfce4-linelight/");
 
322
    system("mkdir /tmp/xfce4-linelight/");
 
323
    while (NULL!=fgets(line, MAX_PATH_LENGTH, search_process))
 
324
    {
 
325
        //remove /n at the end
 
326
        if (strlen(line) != 0 && line[strlen(line)-1] == '\n')
 
327
            line[strlen(line)-1] = '\0' ;
 
328
 
 
329
        sprintf(link_command, "ln -s \"%s\" /tmp/xfce4-linelight/", line);
 
330
        system(link_command);
 
331
    }
 
332
 
 
333
    pclose(search_process);
 
334
    system("thunar /tmp/xfce4-linelight/");
 
335
    return NULL;
 
336
}
 
337
 
 
338
//TODO: remove dublicated code
 
339
void* show_all_search_results_from_section(void* sec)
 
340
{
 
341
    const char *search_string;
 
342
    FILE *search_process;
 
343
    int section;
 
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, "\"");
 
350
 
 
351
    search_process = popen(command, "r");
 
352
 
 
353
    if (search_process == NULL)
 
354
    {
 
355
        xfce_err("locate clould not be executed!");
 
356
        return NULL;
 
357
    }
 
358
 
 
359
    system("rm -r /tmp/xfce4-linelight/");
 
360
    system("mkdir /tmp/xfce4-linelight/");
 
361
    while (NULL!=fgets(line, MAX_PATH_LENGTH, search_process))
 
362
    {
 
363
        section = linelight_get_result_section(linelight,line);
 
364
        if (section == *((int*)sec))
 
365
        {
 
366
            //remove /n at the end
 
367
            // if (strlen(line) != 0 && line[strlen(line)-1] == '\n')
 
368
            //    line[strlen(line)-1] = '\0' ;
 
369
 
 
370
            sprintf(link_command, "ln -s \"%s\" /tmp/xfce4-linelight/", line);
 
371
            system(link_command);
 
372
        }
 
373
    }
 
374
 
 
375
    pclose(search_process);
 
376
    system("thunar /tmp/xfce4-linelight/");
 
377
    free(sec);
 
378
    return NULL;
 
379
}
 
380
 
 
381
void executeAction(char *text)
 
382
{
 
383
    int i;
 
384
 
 
385
    // more... was selected
 
386
    if (strcmp(text,"more...") == 0)
 
387
    {
 
388
        g_thread_create(show_all_search_results, NULL, FALSE, NULL);
 
389
    }
 
390
 
 
391
    //A section was selected
 
392
    for (i =  0;i<SECTION_COUNT; i++)
 
393
    {
 
394
        if (strstr(text,sectionNames[i]) != NULL)
 
395
        {
 
396
            int *section = malloc(sizeof(int));
 
397
            *section = i;
 
398
            g_thread_create(show_all_search_results_from_section, (void*)section, FALSE, NULL);
 
399
        }
 
400
    }
 
401
 
 
402
    //a path was selected
 
403
    executeFile(text);
 
404
}
 
405
 
 
406
static gboolean tree_mouse_selection (GtkWidget *tree,  GdkEventButton *event, GtkWidget *entry)
 
407
{
 
408
    if (event->type == GDK_2BUTTON_PRESS)
 
409
    {
 
410
        GtkTreeSelection *selection;
 
411
        GtkTreeIter iter;
 
412
        GtkTreeModel *model;
 
413
        char *path;
 
414
 
 
415
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
 
416
 
 
417
        if (gtk_tree_selection_get_selected (selection, &model, &iter))
 
418
        {
 
419
            gtk_tree_model_get(model, &iter, TEXT_COL, &path, -1);
 
420
 
 
421
            executeAction(path);
 
422
            g_free(path);
 
423
        }
 
424
        return TRUE;
 
425
    }
 
426
    return FALSE;
 
427
}
 
428
 
 
429
static gboolean tree_selection(GtkWidget *tree, GdkEventKey *event, GtkWidget *entry)
 
430
{
 
431
    if (event->keyval == GDK_Escape || event->keyval == GDK_F4)
 
432
    {
 
433
        linelight_toggle_show_hide(linelight);
 
434
    }
 
435
    else if (event->keyval == GDK_Return)
 
436
    {
 
437
        GtkTreeSelection *selection;
 
438
        GtkTreeIter iter;
 
439
        GtkTreeModel *model;
 
440
        char *path;
 
441
 
 
442
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));;
 
443
 
 
444
        if (gtk_tree_selection_get_selected (selection, &model, &iter))
 
445
        {
 
446
            gtk_tree_model_get(model, &iter, TEXT_COL, &path, -1);
 
447
 
 
448
            executeAction(path);
 
449
            g_free(path);
 
450
        }
 
451
    }
 
452
    else if (event->keyval != GDK_Up && event->keyval != GDK_Down)
 
453
    {
 
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));
 
458
    }
 
459
    return TRUE;
 
460
}
 
461
 
 
462
//callback for the panel button (creates or destroys the main window)
 
463
static void open_search_window_cb(GtkButton *button, XfcePanelPlugin* plugin)
 
464
{
 
465
    linelight_toggle_show_hide(linelight);
 
466
}
 
467
 
 
468
static gboolean esc_event(GtkWidget *w, GdkEventKey *event, GtkWidget *entry)
 
469
{
 
470
    if (event->keyval == GDK_Escape || event->keyval == GDK_F4)
 
471
    {
 
472
        linelight_toggle_show_hide(linelight);
 
473
        return TRUE;
 
474
    }
 
475
    return FALSE;
 
476
}
 
477
 
 
478
static gboolean delete_event(GtkWidget *w, GdkEvent* event,  gpointer   user_data)
 
479
{
 
480
    linelight_toggle_show_hide(linelight);
 
481
    return TRUE;
 
482
}
 
483
 
 
484
/*
 
485
 *  About Dialog
 
486
 */
 
487
 
 
488
static void show_about_cb(XfcePanelPlugin *plugin, gpointer userdata)
 
489
{
 
490
    GtkWidget *dialog;
 
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);
 
492
 
 
493
    xfce_about_info_set_homepage(info,"http://www.ganymede.ch");
 
494
 
 
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));
 
499
 
 
500
    xfce_about_info_free(info);
 
501
}
 
502
 
 
503
/*
 
504
 *  Persistance and Clean-Up
 
505
 */
 
506
 
 
507
static void load_data(XfcePanelPlugin *plugin, LineLightData *data)
 
508
{
 
509
    gchar *file;
 
510
    XfceRc *rc;
 
511
    int i;
 
512
    char sec_enable[] = "section_enabled_#";
 
513
 
 
514
    if (!(file = xfce_panel_plugin_lookup_rc_file(plugin)))
 
515
        return;
 
516
 
 
517
    rc = xfce_rc_simple_open(file,TRUE);
 
518
    g_free(file);
 
519
 
 
520
    if (!rc)
 
521
        return;
 
522
 
 
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++)
 
530
    {
 
531
        sprintf(sec_enable, "section_enabled_%i", i);
 
532
        data->section_enabled[i] = xfce_rc_read_int_entry(rc,sec_enable, TRUE);
 
533
    }
 
534
 
 
535
    xfce_rc_close(rc);
 
536
}
 
537
 
 
538
static void save_data_cb(XfcePanelPlugin *plugin, gpointer userdata)
 
539
{
 
540
    gchar *file;
 
541
    XfceRc *rc;
 
542
    int i;
 
543
    char sec_enable[] = "section_enabled_#";
 
544
 
 
545
    if (!(file = xfce_panel_plugin_save_location(plugin, TRUE)))
 
546
        return;
 
547
 
 
548
    rc = xfce_rc_simple_open(file,FALSE);
 
549
    g_free(file);
 
550
 
 
551
    if (!rc)
 
552
        return;
 
553
 
 
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++)
 
561
    {
 
562
        sprintf(sec_enable, "section_enabled_%i", i);
 
563
        xfce_rc_write_int_entry(rc,sec_enable, linelight->section_enabled[i]);
 
564
    }
 
565
 
 
566
    xfce_rc_close(rc);
 
567
}
 
568
 
 
569
static void clean_up_cb(XfcePanelPlugin *plugin, gpointer userdata)
 
570
{
 
571
    save_data_cb(plugin, userdata);
 
572
    linelight_free(linelight);
 
573
    system("rm -r /tmp/xfce4-linelight/");
 
574
    gdk_threads_leave ();
 
575
}
 
576
 
 
577
/*
 
578
 *  Properties Frame and Callback Methods
 
579
 */
 
580
 
 
581
static void set_max_results_value_cb(GtkWidget *spinner, gpointer userdata)
 
582
{
 
583
    linelight->max_search_results = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner));
 
584
}
 
585
 
 
586
static void min_char_for_search_value_cb(GtkWidget *spinner, gpointer userdata)
 
587
{
 
588
    linelight->min_char_for_search = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner));
 
589
}
 
590
 
 
591
static void toggle_window_decoration_cb(GtkWidget *but, gpointer userdata)
 
592
{
 
593
    linelight->decorated = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(but));
 
594
    gtk_window_set_decorated(GTK_WINDOW (linelight->text_window), linelight->decorated);
 
595
}
 
596
 
 
597
static void section_selection_cb(GtkWidget *but, gpointer userdata)
 
598
{
 
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));
 
614
}
 
615
 
 
616
static void grow_corner_selection_cb(GtkWidget *but, gpointer userdata)
 
617
{
 
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;
 
627
}
 
628
 
 
629
static void showProperties_cb(XfcePanelPlugin *plugin, gpointer userdata)
 
630
{
 
631
    linelight_update_coordinates(linelight);
 
632
    gtk_widget_hide(linelight->text_window);
 
633
    xfce_panel_plugin_block_menu(plugin);
 
634
 
 
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);
 
636
 
 
637
    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
 
638
    g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
 
639
 
 
640
    GtkWidget *table = gtk_table_new(3,4,FALSE);
 
641
    gtk_table_set_col_spacing(GTK_TABLE(table),0,5);
 
642
 
 
643
    //left side of the dialog
 
644
    GtkWidget *section_frame = gtk_frame_new("Section Selection");
 
645
    GtkWidget *section_selection = gtk_vbox_new(FALSE,5);
 
646
 
 
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);
 
651
 
 
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);
 
656
 
 
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);
 
661
 
 
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);
 
666
 
 
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);
 
671
 
 
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);
 
676
 
 
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);
 
681
 
 
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);
 
684
 
 
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);
 
693
 
 
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);
 
701
 
 
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);
 
709
 
 
710
    GtkWidget *corner_frame = gtk_frame_new("Fix Corner When Resizing");
 
711
    GtkWidget *corner_selection = gtk_vbox_new(FALSE,5);
 
712
 
 
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);
 
718
 
 
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);
 
724
 
 
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);
 
730
 
 
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);
 
736
 
 
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);
 
739
 
 
740
 
 
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));
 
745
 
 
746
    linelight_clear_list(linelight);
 
747
    xfce_panel_plugin_unblock_menu(plugin);
 
748
}
 
749
 
 
750
/*
 
751
 *  APPLICATION START METHODS
 
752
 */
 
753
 
 
754
#ifdef __DEBUG__
 
755
int main (int argc, char *argv[])
 
756
{
 
757
    g_type_init ();
 
758
    g_thread_init (NULL);
 
759
    gdk_threads_init();
 
760
    gdk_threads_enter();
 
761
 
 
762
    gtk_init (&argc, &argv);
 
763
 
 
764
 
 
765
    //main window
 
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);
 
777
 
 
778
    gtk_widget_show_all(text_window);
 
779
    gtk_widget_grab_focus(text_window);
 
780
 
 
781
 
 
782
    gtk_main ();
 
783
    gdk_threads_leave ();
 
784
    return 0;
 
785
}
 
786
#else
 
787
// callback for xfce panel (executed on plugin addition)
 
788
static void plugin_create(XfcePanelPlugin *plugin)
 
789
{
 
790
    g_type_init ();   
 
791
    g_thread_init (NULL);
 
792
    gdk_threads_init();
 
793
    gdk_threads_enter();
 
794
 
 
795
    xfce_panel_plugin_menu_show_configure(plugin);
 
796
    xfce_panel_plugin_menu_show_about(plugin);
 
797
 
 
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);
 
803
 
 
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);
 
811
 
 
812
    //main window
 
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);
 
823
 
 
824
    load_data(plugin,linelight);
 
825
    linelight_clear_list(linelight);
 
826
    if(linelight->decorated)
 
827
        gtk_window_set_decorated(GTK_WINDOW (text_window), TRUE);
 
828
    else
 
829
        gtk_window_set_decorated(GTK_WINDOW (text_window), FALSE);
 
830
 
 
831
}
 
832
 
 
833
 
 
834
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(plugin_create);
 
835
 
 
836
#endif