File: bmpinterface.c

package info (click to toggle)
imms 3.0.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 920 kB
  • ctags: 1,195
  • sloc: cpp: 7,224; ansic: 1,872; sh: 186; makefile: 127
file content (177 lines) | stat: -rw-r--r-- 6,398 bytes parent folder | download | duplicates (2)
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
#include <gtk/gtk.h>

#include <bmp/configdb.h>
#include <bmp/util.h>
#include <bmp/plugin.h>

#include "immsconf.h"
#include "cplugin.h"


int use_xidle = 1;
int poll_tag = 0;

GtkWidget *configure_win = NULL, *about_win = NULL, *xidle_button = NULL;

gint poll_func(gpointer unused)
{
    imms_poll();
    return TRUE;
}

void read_config(void)
{
    ConfigDb *cfgfile;

    if ((cfgfile = bmp_cfg_db_open()) != NULL)
    {
        bmp_cfg_db_get_int(cfgfile, "imms", "xidle", &use_xidle);
        bmp_cfg_db_close(cfgfile);
    }
}

void init(void)
{
    imms_init();
    read_config();
    imms_setup(use_xidle);
    poll_tag = gtk_timeout_add(200, poll_func, NULL);
}

void cleanup(void)
{
    imms_cleanup();

    if (poll_tag)
        gtk_timeout_remove(poll_tag);

    poll_tag = 0;
}

void configure_ok_cb(gpointer data)
{
    ConfigDb *cfgfile = bmp_cfg_db_open();

    use_xidle = !!GTK_TOGGLE_BUTTON(xidle_button)->active;

    bmp_cfg_db_set_int(cfgfile, "imms", "xidle", use_xidle);
    bmp_cfg_db_close(cfgfile);

    imms_setup(use_xidle);
    gtk_widget_destroy(configure_win);
}  

#define ADD_CONFIG_CHECKBOX(pref, title, label, descr)                          \
    pref##_frame = gtk_frame_new(title);                                        \
    gtk_box_pack_start(GTK_BOX(configure_vbox), pref##_frame, FALSE, FALSE, 0); \
    pref##_vbox = gtk_vbox_new(FALSE, 10);                                      \
    gtk_container_set_border_width(GTK_CONTAINER(pref##_vbox), 5);              \
    gtk_container_add(GTK_CONTAINER(pref##_frame), pref##_vbox);                \
                                                                                \
    pref##_desc = gtk_label_new(label);                                         \
                                                                                \
    gtk_label_set_line_wrap(GTK_LABEL(pref##_desc), TRUE);                      \
    gtk_label_set_justify(GTK_LABEL(pref##_desc), GTK_JUSTIFY_LEFT);            \
    gtk_misc_set_alignment(GTK_MISC(pref##_desc), 0, 0.5);                      \
    gtk_box_pack_start(GTK_BOX(pref##_vbox), pref##_desc, FALSE, FALSE, 0);     \
    gtk_widget_show(pref##_desc);                                               \
                                                                                \
    pref##_hbox = gtk_hbox_new(FALSE, 5);                                       \
    gtk_box_pack_start(GTK_BOX(pref##_vbox), pref##_hbox, FALSE, FALSE, 0);     \
                                                                                \
    pref##_button = gtk_check_button_new_with_label(descr);                     \
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pref##_button), use_##pref); \
    gtk_box_pack_start(GTK_BOX(pref##_hbox), pref##_button, FALSE, FALSE, 0);   \
                                                                                \
    gtk_widget_show(pref##_frame);                                              \
    gtk_widget_show(pref##_vbox);                                               \
    gtk_widget_show(pref##_button);                                             \
    gtk_widget_show(pref##_hbox);

void configure(void)
{
    GtkWidget *configure_vbox;
    GtkWidget *xidle_hbox, *xidle_vbox, *xidle_frame, *xidle_desc; 
    GtkWidget *configure_bbox, *configure_ok, *configure_cancel;

    if (configure_win)
        return;

    read_config();

    configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect(GTK_OBJECT(configure_win), "destroy",
            GTK_SIGNAL_FUNC(gtk_widget_destroyed), &configure_win);
    gtk_window_set_title(GTK_WINDOW(configure_win), "IMMS Configuration");

    gtk_container_set_border_width(GTK_CONTAINER(configure_win), 10);

    configure_vbox = gtk_vbox_new(FALSE, 10);
    gtk_container_add(GTK_CONTAINER(configure_win), configure_vbox);

    ADD_CONFIG_CHECKBOX(xidle, "Idleness", 
            "Disable this option if you use BEEP on a dedicated machine",
            "Use X idleness statistics");

    /* Buttons */
    configure_bbox = gtk_hbutton_box_new();
    gtk_button_box_set_layout(GTK_BUTTON_BOX(configure_bbox), GTK_BUTTONBOX_END);
    gtk_button_box_set_spacing(GTK_BUTTON_BOX(configure_bbox), 5);
    gtk_box_pack_start(GTK_BOX(configure_vbox), configure_bbox, FALSE, FALSE, 0);

    configure_ok = gtk_button_new_with_label("Ok");
    gtk_signal_connect(GTK_OBJECT(configure_ok), "clicked",
            GTK_SIGNAL_FUNC(configure_ok_cb), NULL);
    GTK_WIDGET_SET_FLAGS(configure_ok, GTK_CAN_DEFAULT);
    gtk_box_pack_start(GTK_BOX(configure_bbox), configure_ok, TRUE, TRUE, 0);
    gtk_widget_show(configure_ok);
    gtk_widget_grab_default(configure_ok);

    configure_cancel = gtk_button_new_with_label("Cancel");
    gtk_signal_connect_object(GTK_OBJECT(configure_cancel), "clicked",
            GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(configure_win));
    GTK_WIDGET_SET_FLAGS(configure_cancel, GTK_CAN_DEFAULT);
    gtk_box_pack_start(GTK_BOX(configure_bbox), configure_cancel, TRUE, TRUE, 0);
    gtk_widget_show(configure_cancel);
    gtk_widget_show(configure_bbox);
    gtk_widget_show(configure_vbox);
    gtk_widget_show(configure_win);
}

void about(void)
{
    if (about_win)
        return;

    about_win = xmms_show_message(
            "About IMMS",
            PACKAGE_STRING "\n\n"
            "Intelligent Multimedia Management System" "\n\n"
            "IMMS is an intelligent playlist plug-in for BPM" "\n"
            "that tracks your listening patterns" "\n"
            "and dynamically adapts to your taste." "\n\n"
            "It is incredibly unobtrusive and easy to use" "\n"
            "as it requires no direct user interaction." "\n\n"
            "For more information please visit" "\n"
            "http://www.luminal.org/wiki/index.php/IMMS" "\n\n"
            "Written by" "\n"
            "Michael \"mag\" Grigoriev <mag@luminal.org>",
            "Dismiss", FALSE, NULL, NULL);

    gtk_signal_connect(GTK_OBJECT(about_win), "destroy",
            GTK_SIGNAL_FUNC(gtk_widget_destroyed), &about_win);
}

GeneralPlugin imms_gp =
{
    NULL,           /* handle */
    NULL,           /* plugin filename */
    -1,             /* session */
    PACKAGE_STRING, /* description */
    init,
    about,
    configure,
    cleanup
};

GeneralPlugin *get_gplugin_info(void) { return &imms_gp; }