Tue, 17 Oct 2006 08:13:41 +0000
[gaim-migrate @ 17495]
This should fix the statusbox issues that were keeping us from releasing beta
4 (and which were just really annoying). Thakn sadrul for most of this, I just
added the if (index == -1) bit. Anyway, the way this works now is that for
saved/popular statuses the primitive underlying that status is where the
dropdown for the statusbox starts. If we don't like that we can change it but
I'm not sure we'll find something better.
Also, this might plug a couple leaks, I'm not really sure but it certainly
looks right.
Up next, the patch to make the docklet use the per-protocol statuses in the
top section.
| 12737 | 1 | #include "internal.h" |
| 2 | ||
| 3 | #include "debug.h" | |
| 4 | #include "log.h" | |
| 5 | #include "plugin.h" | |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13090
diff
changeset
|
6 | #include "util.h" |
| 12737 | 7 | #include "version.h" |
| 8 | ||
| 9 | #include "gtkconv.h" | |
| 10 | #include "gtkplugin.h" | |
| 11 | ||
|
12851
96079cc66acf
[gaim-migrate @ 15201]
Richard Laager <rlaager@pidgin.im>
parents:
12848
diff
changeset
|
12 | #include <time.h> |
|
96079cc66acf
[gaim-migrate @ 15201]
Richard Laager <rlaager@pidgin.im>
parents:
12848
diff
changeset
|
13 | |
| 12737 | 14 | static GaimPluginPrefFrame * |
| 15 | get_plugin_pref_frame(GaimPlugin *plugin) | |
| 16 | { | |
| 17 | GaimPluginPrefFrame *frame; | |
| 18 | GaimPluginPref *ppref; | |
| 19 | ||
| 20 | frame = gaim_plugin_pref_frame_new(); | |
| 21 | ||
| 22 | ppref = gaim_plugin_pref_new_with_label(_("Timestamp Format Options")); | |
| 23 | gaim_plugin_pref_frame_add(frame, ppref); | |
| 24 | ||
| 25 | ppref = gaim_plugin_pref_new_with_name_and_label( | |
| 26 | "/plugins/gtk/timestamp_format/force_24hr", | |
| 27 | _("_Force (traditional Gaim) 24-hour time format")); | |
| 28 | gaim_plugin_pref_frame_add(frame, ppref); | |
| 29 | ||
| 30 | ppref = gaim_plugin_pref_new_with_label(_("Show dates in...")); | |
| 31 | gaim_plugin_pref_frame_add(frame, ppref); | |
| 32 | ||
| 33 | ppref = gaim_plugin_pref_new_with_name_and_label( | |
| 34 | "/plugins/gtk/timestamp_format/use_dates/conversation", | |
| 35 | _("Co_nversations:")); | |
| 36 | gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); | |
|
13090
aee4ed853ff3
[gaim-migrate @ 15451]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13054
diff
changeset
|
37 | gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); |
|
aee4ed853ff3
[gaim-migrate @ 15451]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13054
diff
changeset
|
38 | gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); |
|
aee4ed853ff3
[gaim-migrate @ 15451]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13054
diff
changeset
|
39 | gaim_plugin_pref_add_choice(ppref, _("Always"), "always"); |
| 12737 | 40 | gaim_plugin_pref_frame_add(frame, ppref); |
| 41 | ||
| 42 | ppref = gaim_plugin_pref_new_with_name_and_label( | |
| 43 | "/plugins/gtk/timestamp_format/use_dates/log", | |
|
12848
a6cc4c3c950f
[gaim-migrate @ 15198]
Richard Laager <rlaager@pidgin.im>
parents:
12737
diff
changeset
|
44 | _("_Message Logs:")); |
| 12737 | 45 | gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); |
|
13090
aee4ed853ff3
[gaim-migrate @ 15451]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13054
diff
changeset
|
46 | gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); |
|
aee4ed853ff3
[gaim-migrate @ 15451]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13054
diff
changeset
|
47 | gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); |
|
aee4ed853ff3
[gaim-migrate @ 15451]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13054
diff
changeset
|
48 | gaim_plugin_pref_add_choice(ppref, _("Always"), "always"); |
| 12737 | 49 | gaim_plugin_pref_frame_add(frame, ppref); |
| 50 | ||
| 51 | return frame; | |
| 52 | } | |
| 53 | ||
| 54 | static char *timestamp_cb_common(GaimConversation *conv, | |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
55 | time_t t, |
| 12737 | 56 | gboolean force, |
| 57 | const char *dates) | |
| 58 | { | |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
59 | struct tm *tm = localtime(&t); |
| 12737 | 60 | g_return_val_if_fail(conv != NULL, NULL); |
| 61 | g_return_val_if_fail(dates != NULL, NULL); | |
| 62 | ||
| 63 | if (!strcmp(dates, "always") || | |
| 64 | (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && | |
|
12848
a6cc4c3c950f
[gaim-migrate @ 15198]
Richard Laager <rlaager@pidgin.im>
parents:
12737
diff
changeset
|
65 | !strcmp(dates, "chats")) || |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
66 | (time(NULL) > (mktime(tm) + 20*60))) |
| 12737 | 67 | { |
| 68 | if (force) | |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13090
diff
changeset
|
69 | return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); |
| 12737 | 70 | else |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13090
diff
changeset
|
71 | return g_strdup(gaim_date_format_long(tm)); |
| 12737 | 72 | } |
| 73 | ||
| 74 | if (force) | |
|
13115
ed3680c839d8
[gaim-migrate @ 15476]
Richard Laager <rlaager@pidgin.im>
parents:
13105
diff
changeset
|
75 | return g_strdup(gaim_utf8_strftime("%H:%M:%S", tm)); |
| 12737 | 76 | |
| 77 | return NULL; | |
| 78 | } | |
| 79 | ||
| 80 | static char *conversation_timestamp_cb(GaimConversation *conv, | |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
81 | time_t t, gpointer data) |
| 12737 | 82 | { |
| 83 | gboolean force = gaim_prefs_get_bool( | |
| 84 | "/plugins/gtk/timestamp_format/force_24hr"); | |
| 85 | const char *dates = gaim_prefs_get_string( | |
| 86 | "/plugins/gtk/timestamp_format/use_dates/conversation"); | |
|
13054
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
87 | |
|
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
88 | g_return_val_if_fail(conv != NULL, NULL); |
|
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
89 | |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
90 | return timestamp_cb_common(conv, t, force, dates); |
| 12737 | 91 | } |
| 92 | ||
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
93 | static char *log_timestamp_cb(GaimLog *log, time_t t, gpointer data) |
| 12737 | 94 | { |
| 95 | gboolean force = gaim_prefs_get_bool( | |
| 96 | "/plugins/gtk/timestamp_format/force_24hr"); | |
| 97 | const char *dates = gaim_prefs_get_string( | |
| 98 | "/plugins/gtk/timestamp_format/use_dates/log"); | |
| 99 | ||
|
13054
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
100 | g_return_val_if_fail(log != NULL, NULL); |
|
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
101 | |
| 12737 | 102 | if (log->type == GAIM_LOG_SYSTEM) |
| 103 | { | |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
104 | if (force) { |
|
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
105 | struct tm *tm = localtime(&t); |
|
13105
8f9c66e4af87
[gaim-migrate @ 15466]
Richard Laager <rlaager@pidgin.im>
parents:
13090
diff
changeset
|
106 | return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
107 | } else { |
| 12737 | 108 | return NULL; |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
109 | } |
| 12737 | 110 | } |
| 111 | ||
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
112 | return timestamp_cb_common(log->conv, t, force, dates); |
| 12737 | 113 | } |
| 114 | ||
| 115 | static gboolean | |
| 116 | plugin_load(GaimPlugin *plugin) | |
| 117 | { | |
| 118 | gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp", | |
| 119 | plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL); | |
| 120 | gaim_signal_connect(gaim_log_get_handle(), "log-timestamp", | |
| 121 | plugin, GAIM_CALLBACK(log_timestamp_cb), NULL); | |
| 122 | return TRUE; | |
| 123 | } | |
| 124 | ||
| 125 | static gboolean | |
| 126 | plugin_unload(GaimPlugin *plugin) | |
| 127 | { | |
| 128 | return TRUE; | |
| 129 | } | |
| 130 | ||
| 131 | static GaimPluginUiInfo prefs_info = { | |
| 132 | get_plugin_pref_frame, | |
| 133 | 0, /* page num (Reserved) */ | |
| 134 | NULL /* frame (Reserved) */ | |
| 135 | }; | |
| 136 | ||
| 137 | static GaimPluginInfo info = | |
| 138 | { | |
| 139 | GAIM_PLUGIN_MAGIC, | |
| 140 | GAIM_MAJOR_VERSION, | |
| 141 | GAIM_MINOR_VERSION, | |
| 142 | GAIM_PLUGIN_STANDARD, /**< type */ | |
| 143 | GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ | |
| 144 | 0, /**< flags */ | |
| 145 | NULL, /**< dependencies */ | |
| 146 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 147 | ||
| 148 | NULL, /**< id */ | |
| 149 | N_("Message Timestamp Formats"), /**< name */ | |
| 150 | VERSION, /**< version */ | |
| 151 | /** summary */ | |
| 152 | N_("Customizes the message timestamp formats."), | |
| 153 | /** description */ | |
| 154 | N_("This plugin allows the user to customize " | |
| 155 | "conversation and logging message timestamp " | |
| 156 | "formats."), | |
| 157 | "Richard Laager <rlaager@users.sf.net>", /**< author */ | |
| 158 | GAIM_WEBSITE, /**< homepage */ | |
| 159 | ||
| 160 | plugin_load, /**< load */ | |
| 161 | plugin_unload, /**< unload */ | |
| 162 | NULL, /**< destroy */ | |
| 163 | ||
| 164 | NULL, /**< ui_info */ | |
| 165 | NULL, /**< extra_info */ | |
| 166 | &prefs_info, /**< prefs_info */ | |
| 167 | NULL /**< actions */ | |
| 168 | }; | |
| 169 | ||
| 170 | static void | |
| 171 | init_plugin(GaimPlugin *plugin) | |
| 172 | { | |
| 173 | gaim_prefs_add_none("/plugins/gtk"); | |
| 174 | gaim_prefs_add_none("/plugins/gtk/timestamp_format"); | |
| 175 | ||
| 176 | gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); | |
| 177 | ||
| 178 | gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); | |
| 179 | gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); | |
| 180 | gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); | |
| 181 | } | |
| 182 | ||
| 183 | GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info) |