Mercurial > pidgin
annotate plugins/timestamp_format.c @ 13093:4f615c9fb63a
[gaim-migrate @ 15455]
Since we try to discourage use of CVS, let's not talk about it in the segfault message. That line doesn't really provide any useful information to the average user anyway.
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Thu, 02 Feb 2006 05:54:51 +0000 |
| parents | b553326bc468 |
| children | e1e5462b7d81 |
| rev | line source |
|---|---|
| 12737 | 1 #include "internal.h" |
| 2 | |
| 3 #include "debug.h" | |
| 4 #include "log.h" | |
| 5 #include "plugin.h" | |
| 6 #include "version.h" | |
| 7 | |
| 8 #include "gtkconv.h" | |
| 9 #include "gtkplugin.h" | |
| 10 | |
|
12851
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
11 #include <time.h> |
|
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
12 |
| 12737 | 13 static GaimPluginPrefFrame * |
| 14 get_plugin_pref_frame(GaimPlugin *plugin) | |
| 15 { | |
| 16 GaimPluginPrefFrame *frame; | |
| 17 GaimPluginPref *ppref; | |
| 18 | |
| 19 frame = gaim_plugin_pref_frame_new(); | |
| 20 | |
| 21 ppref = gaim_plugin_pref_new_with_label(_("Timestamp Format Options")); | |
| 22 gaim_plugin_pref_frame_add(frame, ppref); | |
| 23 | |
| 24 ppref = gaim_plugin_pref_new_with_name_and_label( | |
| 25 "/plugins/gtk/timestamp_format/force_24hr", | |
| 26 _("_Force (traditional Gaim) 24-hour time format")); | |
| 27 gaim_plugin_pref_frame_add(frame, ppref); | |
| 28 | |
| 29 ppref = gaim_plugin_pref_new_with_label(_("Show dates in...")); | |
| 30 gaim_plugin_pref_frame_add(frame, ppref); | |
| 31 | |
| 32 ppref = gaim_plugin_pref_new_with_name_and_label( | |
| 33 "/plugins/gtk/timestamp_format/use_dates/conversation", | |
| 34 _("Co_nversations:")); | |
| 35 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); | |
| 13089 | 36 gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); |
| 37 gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); | |
| 38 gaim_plugin_pref_add_choice(ppref, _("Always"), "always"); | |
| 12737 | 39 gaim_plugin_pref_frame_add(frame, ppref); |
| 40 | |
| 41 ppref = gaim_plugin_pref_new_with_name_and_label( | |
| 42 "/plugins/gtk/timestamp_format/use_dates/log", | |
|
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
43 _("_Message Logs:")); |
| 12737 | 44 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); |
| 13089 | 45 gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); |
| 46 gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); | |
| 47 gaim_plugin_pref_add_choice(ppref, _("Always"), "always"); | |
| 12737 | 48 gaim_plugin_pref_frame_add(frame, ppref); |
| 49 | |
| 50 return frame; | |
| 51 } | |
| 52 | |
| 53 static char *timestamp_cb_common(GaimConversation *conv, | |
| 54 const struct tm *tm, | |
| 55 gboolean force, | |
| 56 const char *dates) | |
| 57 { | |
| 58 char buf[64]; | |
| 59 | |
| 60 g_return_val_if_fail(conv != NULL, NULL); | |
| 61 g_return_val_if_fail(tm != NULL, NULL); | |
| 62 g_return_val_if_fail(dates != NULL, NULL); | |
| 63 | |
| 64 if (!strcmp(dates, "always") || | |
| 65 (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && | |
|
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
66 !strcmp(dates, "chats")) || |
|
12851
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
67 (time(NULL) > (mktime((struct tm *)tm) + 20*60))) |
| 12737 | 68 { |
| 69 if (force) | |
| 70 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); | |
| 71 else | |
| 72 strftime(buf, sizeof(buf), "%x %X", tm); | |
| 73 | |
| 74 return g_strdup(buf); | |
| 75 } | |
| 76 | |
| 77 if (force) | |
| 78 { | |
| 79 strftime(buf, sizeof(buf), "%H:%M:%S", tm); | |
| 80 return g_strdup(buf); | |
| 81 } | |
| 82 | |
| 83 return NULL; | |
| 84 } | |
| 85 | |
| 86 static char *conversation_timestamp_cb(GaimConversation *conv, | |
| 87 const struct tm *tm, gpointer data) | |
| 88 { | |
| 89 gboolean force = gaim_prefs_get_bool( | |
| 90 "/plugins/gtk/timestamp_format/force_24hr"); | |
| 91 const char *dates = gaim_prefs_get_string( | |
| 92 "/plugins/gtk/timestamp_format/use_dates/conversation"); | |
|
13054
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
93 |
|
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
94 g_return_val_if_fail(conv != NULL, NULL); |
|
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
95 g_return_val_if_fail(tm != NULL, NULL); |
|
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
96 |
| 12737 | 97 return timestamp_cb_common(conv, tm, force, dates); |
| 98 } | |
| 99 | |
| 100 static char *log_timestamp_cb(GaimLog *log, | |
| 101 const struct tm *tm, gpointer data) | |
| 102 { | |
| 103 gboolean force = gaim_prefs_get_bool( | |
| 104 "/plugins/gtk/timestamp_format/force_24hr"); | |
| 105 const char *dates = gaim_prefs_get_string( | |
| 106 "/plugins/gtk/timestamp_format/use_dates/log"); | |
| 107 | |
|
13054
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
108 g_return_val_if_fail(log != NULL, NULL); |
|
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
109 g_return_val_if_fail(tm != NULL, NULL); |
|
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
110 |
| 12737 | 111 if (log->type == GAIM_LOG_SYSTEM) |
| 112 { | |
| 113 if (force) | |
| 114 { | |
| 115 char buf[64]; | |
| 116 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); | |
| 117 return g_strdup(buf); | |
| 118 } | |
| 119 else | |
| 120 return NULL; | |
| 121 } | |
| 122 | |
| 123 return timestamp_cb_common(log->conv, tm, force, dates); | |
| 124 } | |
| 125 | |
| 126 static gboolean | |
| 127 plugin_load(GaimPlugin *plugin) | |
| 128 { | |
| 129 gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp", | |
| 130 plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL); | |
| 131 gaim_signal_connect(gaim_log_get_handle(), "log-timestamp", | |
| 132 plugin, GAIM_CALLBACK(log_timestamp_cb), NULL); | |
| 133 return TRUE; | |
| 134 } | |
| 135 | |
| 136 static gboolean | |
| 137 plugin_unload(GaimPlugin *plugin) | |
| 138 { | |
| 139 return TRUE; | |
| 140 } | |
| 141 | |
| 142 static GaimPluginUiInfo prefs_info = { | |
| 143 get_plugin_pref_frame, | |
| 144 0, /* page num (Reserved) */ | |
| 145 NULL /* frame (Reserved) */ | |
| 146 }; | |
| 147 | |
| 148 static GaimPluginInfo info = | |
| 149 { | |
| 150 GAIM_PLUGIN_MAGIC, | |
| 151 GAIM_MAJOR_VERSION, | |
| 152 GAIM_MINOR_VERSION, | |
| 153 GAIM_PLUGIN_STANDARD, /**< type */ | |
| 154 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ | |
| 155 0, /**< flags */ | |
| 156 NULL, /**< dependencies */ | |
| 157 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 158 | |
| 159 NULL, /**< id */ | |
| 160 N_("Message Timestamp Formats"), /**< name */ | |
| 161 VERSION, /**< version */ | |
| 162 /** summary */ | |
| 163 N_("Customizes the message timestamp formats."), | |
| 164 /** description */ | |
| 165 N_("This plugin allows the user to customize " | |
| 166 "conversation and logging message timestamp " | |
| 167 "formats."), | |
| 168 "Richard Laager <rlaager@users.sf.net>", /**< author */ | |
| 169 GAIM_WEBSITE, /**< homepage */ | |
| 170 | |
| 171 plugin_load, /**< load */ | |
| 172 plugin_unload, /**< unload */ | |
| 173 NULL, /**< destroy */ | |
| 174 | |
| 175 NULL, /**< ui_info */ | |
| 176 NULL, /**< extra_info */ | |
| 177 &prefs_info, /**< prefs_info */ | |
| 178 NULL /**< actions */ | |
| 179 }; | |
| 180 | |
| 181 static void | |
| 182 init_plugin(GaimPlugin *plugin) | |
| 183 { | |
| 184 gaim_prefs_add_none("/plugins/gtk"); | |
| 185 gaim_prefs_add_none("/plugins/gtk/timestamp_format"); | |
| 186 | |
| 187 gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); | |
| 188 | |
| 189 gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); | |
| 190 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); | |
| 191 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); | |
| 192 } | |
| 193 | |
| 194 GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info) |
