~ubuntu-branches/ubuntu/karmic/pidgin-musictracker/karmic

« back to all changes in this revision

Viewing changes to src/actions.c

  • Committer: Bazaar Package Importer
  • Author(s): Craig Small
  • Date: 2008-11-03 10:24:23 UTC
  • Revision ID: james.westby@ubuntu.com-20081103102423-36ndksn1tdwg96xm
Tags: upstream-0.4.11
ImportĀ upstreamĀ versionĀ 0.4.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <gtk/gtk.h>
 
2
#include <string.h>
 
3
#include "actions.h"
 
4
#include "musictracker.h"
 
5
#include "utils.h"
 
6
#include <gtkblist.h>
 
7
 
 
8
void
 
9
accept_dialog(GtkDialog* dialog)
 
10
{
 
11
        gtk_dialog_response(dialog, GTK_RESPONSE_ACCEPT);
 
12
}
 
13
 
 
14
gboolean
 
15
input_dialog(const char *title, char *buf, int len)
 
16
{
 
17
        GtkWidget *dialog = gtk_dialog_new();
 
18
        gtk_window_set_title(GTK_WINDOW(dialog), "MusicTracker");
 
19
        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
 
20
 
 
21
        gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
 
22
        gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
 
23
 
 
24
        GtkWidget *label = gtk_label_new(title);
 
25
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE,
 
26
                        5);
 
27
 
 
28
        GtkWidget *entry = gtk_entry_new_with_max_length(len);
 
29
        gtk_entry_set_text(GTK_ENTRY(entry), buf);
 
30
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
 
31
                        TRUE, TRUE, 5);
 
32
        g_signal_connect_swapped(entry, "activate", 
 
33
                        G_CALLBACK(accept_dialog), dialog);
 
34
 
 
35
        gtk_widget_show_all(dialog);
 
36
 
 
37
        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
 
38
                strncpy(buf, gtk_entry_get_text(GTK_ENTRY(entry)), len);
 
39
                gtk_widget_destroy(dialog);
 
40
                return TRUE;
 
41
        }
 
42
        gtk_widget_destroy (dialog);
 
43
        return FALSE;
 
44
}
 
45
 
 
46
//--------------------------------------------------------------------
 
47
 
 
48
void
 
49
action_off_status(PurplePluginAction *action)
 
50
{
 
51
        char buf[STRLEN];
 
52
        strncpy(buf, purple_prefs_get_string("/plugins/core/musictracker/string_off"), STRLEN);
 
53
        if (input_dialog("Status to Set When Player is OFF:", buf, STRLEN)) {
 
54
                purple_prefs_set_string("/plugins/core/musictracker/string_off",
 
55
                                buf);
 
56
        }
 
57
}
 
58
 
 
59
//--------------------------------------------------------------------
 
60
 
 
61
void
 
62
action_toggle_status(PurplePluginAction *action)
 
63
{
 
64
        const char *label;
 
65
        gboolean flag = !purple_prefs_get_bool("/plugins/core/musictracker/bool_disabled");
 
66
 
 
67
        if (flag)
 
68
          {
 
69
            set_userstatus_for_active_accounts("", 0);
 
70
            label = "Activate Status Changing";
 
71
          }
 
72
        else
 
73
          {
 
74
            label = "Deactivate Status Changing";
 
75
          }
 
76
 
 
77
        purple_prefs_set_bool("/plugins/core/musictracker/bool_disabled", flag);
 
78
 
 
79
        // update label for action
 
80
        g_free(action->label);
 
81
        action->label = g_strdup(label);
 
82
        
 
83
        // force pidgin to update the tools menu
 
84
        pidgin_blist_update_plugin_actions();
 
85
}
 
86
 
 
87
//--------------------------------------------------------------------
 
88
 
 
89
GList*
 
90
actions_list(PurplePlugin *plugin, gpointer context)
 
91
{
 
92
        GList *list = 0;
 
93
        PurplePluginAction *act;
 
94
 
 
95
        gboolean flag = purple_prefs_get_bool("/plugins/core/musictracker/bool_disabled");
 
96
        act = purple_plugin_action_new(flag ? "Activate Status Changing" : "Deactivate Status Changing", action_toggle_status);
 
97
        list = g_list_append(list, act);
 
98
 
 
99
        act = purple_plugin_action_new("Change Player-Off Status...", action_off_status);
 
100
        list = g_list_append(list, act);
 
101
 
 
102
        return list;
 
103
}
 
104