Mon, 26 Mar 2007 01:11:46 +0000
disapproval of revision '7401338df45b641419c8302df0350b6ca45917fa'
| 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 | |
| 15884 | 14 | static PurplePluginPrefFrame * |
| 15 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 12737 | 16 | { |
| 15884 | 17 | PurplePluginPrefFrame *frame; |
| 18 | PurplePluginPref *ppref; | |
| 12737 | 19 | |
| 15884 | 20 | frame = purple_plugin_pref_frame_new(); |
| 12737 | 21 | |
| 15884 | 22 | ppref = purple_plugin_pref_new_with_label(_("Timestamp Format Options")); |
| 23 | purple_plugin_pref_frame_add(frame, ppref); | |
| 12737 | 24 | |
| 15884 | 25 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 12737 | 26 | "/plugins/gtk/timestamp_format/force_24hr", |
|
15442
2ff7f5308727
I think this is all the instances of 'Gaim' within pidgin/
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
27 | _("_Force (traditional " PIDGIN_NAME ") 24-hour time format")); |
| 15884 | 28 | purple_plugin_pref_frame_add(frame, ppref); |
| 12737 | 29 | |
| 15884 | 30 | ppref = purple_plugin_pref_new_with_label(_("Show dates in...")); |
| 31 | purple_plugin_pref_frame_add(frame, ppref); | |
| 12737 | 32 | |
| 15884 | 33 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 12737 | 34 | "/plugins/gtk/timestamp_format/use_dates/conversation", |
| 35 | _("Co_nversations:")); | |
| 15884 | 36 | purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_CHOICE); |
| 37 | purple_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); | |
| 38 | purple_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); | |
| 39 | purple_plugin_pref_add_choice(ppref, _("Always"), "always"); | |
| 40 | purple_plugin_pref_frame_add(frame, ppref); | |
| 12737 | 41 | |
| 15884 | 42 | ppref = purple_plugin_pref_new_with_name_and_label( |
| 12737 | 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:")); |
| 15884 | 45 | purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_CHOICE); |
| 46 | purple_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); | |
| 47 | purple_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); | |
| 48 | purple_plugin_pref_add_choice(ppref, _("Always"), "always"); | |
| 49 | purple_plugin_pref_frame_add(frame, ppref); | |
| 12737 | 50 | |
| 51 | return frame; | |
| 52 | } | |
| 53 | ||
| 15884 | 54 | static char *timestamp_cb_common(PurpleConversation *conv, |
|
14049
c15c41423e19
[gaim-migrate @ 16559]
Richard Laager <rlaager@pidgin.im>
parents:
13115
diff
changeset
|
55 | time_t t, |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
56 | gboolean show_date, |
| 12737 | 57 | gboolean force, |
| 58 | const char *dates) | |
| 59 | { | |
| 60 | g_return_val_if_fail(dates != NULL, NULL); | |
| 61 | ||
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
62 | if (show_date || |
|
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
63 | !strcmp(dates, "always") || |
| 15884 | 64 | (conv != NULL && purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT && !strcmp(dates, "chats"))) |
| 12737 | 65 | { |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
66 | struct tm *tm = localtime(&t); |
| 12737 | 67 | if (force) |
| 15884 | 68 | return g_strdup(purple_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); |
| 12737 | 69 | else |
| 15884 | 70 | return g_strdup(purple_date_format_long(tm)); |
| 12737 | 71 | } |
| 72 | ||
| 73 | if (force) | |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
74 | { |
|
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
75 | struct tm *tm = localtime(&t); |
| 15884 | 76 | return g_strdup(purple_utf8_strftime("%H:%M:%S", tm)); |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
77 | } |
| 12737 | 78 | |
| 79 | return NULL; | |
| 80 | } | |
| 81 | ||
| 15884 | 82 | static char *conversation_timestamp_cb(PurpleConversation *conv, |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
83 | time_t t, gboolean show_date, gpointer data) |
| 12737 | 84 | { |
| 15884 | 85 | gboolean force = purple_prefs_get_bool( |
| 12737 | 86 | "/plugins/gtk/timestamp_format/force_24hr"); |
| 15884 | 87 | const char *dates = purple_prefs_get_string( |
| 12737 | 88 | "/plugins/gtk/timestamp_format/use_dates/conversation"); |
|
13054
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
89 | |
|
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
90 | g_return_val_if_fail(conv != NULL, NULL); |
|
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
91 | |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
92 | return timestamp_cb_common(conv, t, show_date, force, dates); |
| 12737 | 93 | } |
| 94 | ||
| 15884 | 95 | static char *log_timestamp_cb(PurpleLog *log, time_t t, gboolean show_date, gpointer data) |
| 12737 | 96 | { |
| 15884 | 97 | gboolean force = purple_prefs_get_bool( |
| 12737 | 98 | "/plugins/gtk/timestamp_format/force_24hr"); |
| 15884 | 99 | const char *dates = purple_prefs_get_string( |
| 12737 | 100 | "/plugins/gtk/timestamp_format/use_dates/log"); |
| 101 | ||
|
13054
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
102 | g_return_val_if_fail(log != NULL, NULL); |
|
6d323387986e
[gaim-migrate @ 15416]
Richard Laager <rlaager@pidgin.im>
parents:
12851
diff
changeset
|
103 | |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
104 | return timestamp_cb_common(log->conv, t, show_date, force, dates); |
| 12737 | 105 | } |
| 106 | ||
| 107 | static gboolean | |
| 15884 | 108 | plugin_load(PurplePlugin *plugin) |
| 12737 | 109 | { |
| 15884 | 110 | purple_signal_connect(pidgin_conversations_get_handle(), "conversation-timestamp", |
| 111 | plugin, PURPLE_CALLBACK(conversation_timestamp_cb), NULL); | |
| 112 | purple_signal_connect(purple_log_get_handle(), "log-timestamp", | |
| 113 | plugin, PURPLE_CALLBACK(log_timestamp_cb), NULL); | |
| 12737 | 114 | return TRUE; |
| 115 | } | |
| 116 | ||
| 117 | static gboolean | |
| 15884 | 118 | plugin_unload(PurplePlugin *plugin) |
| 12737 | 119 | { |
| 120 | return TRUE; | |
| 121 | } | |
| 122 | ||
| 15884 | 123 | static PurplePluginUiInfo prefs_info = { |
| 12737 | 124 | get_plugin_pref_frame, |
| 125 | 0, /* page num (Reserved) */ | |
| 126 | NULL /* frame (Reserved) */ | |
| 127 | }; | |
| 128 | ||
| 15884 | 129 | static PurplePluginInfo info = |
| 12737 | 130 | { |
| 15884 | 131 | PURPLE_PLUGIN_MAGIC, |
| 132 | PURPLE_MAJOR_VERSION, | |
| 133 | PURPLE_MINOR_VERSION, | |
| 134 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
|
15575
bd1e13b63e4b
In Pidgin, display a full date on the timestamp of the first message to
Richard Laager <rlaager@pidgin.im>
parents:
15562
diff
changeset
|
135 | PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ |
| 12737 | 136 | 0, /**< flags */ |
| 137 | NULL, /**< dependencies */ | |
| 15884 | 138 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 12737 | 139 | |
| 140 | NULL, /**< id */ | |
| 141 | N_("Message Timestamp Formats"), /**< name */ | |
| 142 | VERSION, /**< version */ | |
| 143 | /** summary */ | |
| 144 | N_("Customizes the message timestamp formats."), | |
| 145 | /** description */ | |
| 146 | N_("This plugin allows the user to customize " | |
| 147 | "conversation and logging message timestamp " | |
| 148 | "formats."), | |
|
15629
a2261cb315e2
Switching to my pidgin.im e-mail address, which I think fits nicely and seems professional.
Richard Laager <rlaager@pidgin.im>
parents:
15626
diff
changeset
|
149 | "Richard Laager <rlaager@pidgin.im>", /**< author */ |
| 15884 | 150 | PURPLE_WEBSITE, /**< homepage */ |
| 12737 | 151 | |
| 152 | plugin_load, /**< load */ | |
| 153 | plugin_unload, /**< unload */ | |
| 154 | NULL, /**< destroy */ | |
| 155 | ||
| 156 | NULL, /**< ui_info */ | |
| 157 | NULL, /**< extra_info */ | |
| 158 | &prefs_info, /**< prefs_info */ | |
| 159 | NULL /**< actions */ | |
| 160 | }; | |
| 161 | ||
| 162 | static void | |
| 15884 | 163 | init_plugin(PurplePlugin *plugin) |
| 12737 | 164 | { |
| 15884 | 165 | purple_prefs_add_none("/plugins/gtk"); |
| 166 | purple_prefs_add_none("/plugins/gtk/timestamp_format"); | |
| 12737 | 167 | |
| 15884 | 168 | purple_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); |
| 12737 | 169 | |
| 15884 | 170 | purple_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); |
| 171 | purple_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); | |
| 172 | purple_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); | |
| 12737 | 173 | } |
| 174 | ||
| 15884 | 175 | PURPLE_INIT_PLUGIN(timestamp_format, init_plugin, info) |