root/trunk/src/tmut-shared.c
| Revision 81 (checked in by pvanhoof, 4 months ago) |
|---|
| Line | |
|---|---|
| 1 | /* TMut |
| 2 | * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with self library; if not, write to the |
| 16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #if HAVE_CONFIG_H |
| 21 | #include "config.h" |
| 22 | #endif |
| 23 | |
| 24 | #include <gtk/gtk.h> |
| 25 | #include <glib/gi18n-lib.h> |
| 26 | |
| 27 | #include <tny-account-store.h> |
| 28 | #include <tny-account-store-view.h> |
| 29 | |
| 30 | |
| 31 | #include "tmut-platform-factory.h" |
| 32 | #include "tmut-menu-view.h" |
| 33 | #include "tmut-shell-window.h" |
| 34 | |
| 35 | TnyPlatformFactory *platfact = NULL; |
| 36 | GHashTable *send_queues = NULL; |
| 37 | |
| 38 | gchar * |
| 39 | _get_readable_date (time_t mtime) |
| 40 | { |
| 41 | time_t now; |
| 42 | struct tm file_time; |
| 43 | |
| 44 | /** |
| 45 | * We reuse a static char. Now hold your breath and listen. This is not |
| 46 | * wrong and I'll explain why: each component that uses this function |
| 47 | * is called from the Gtk+ context. The Gtk+ context can never run in |
| 48 | * parallel with another context because Gtk+ is locked using its |
| 49 | * gdk_threads_enter/leave lock. This means that there's always at most |
| 50 | * one thread doing Gtk+ things. This means that this function does not |
| 51 | * have to be thread safe. And that means that we can have a static |
| 52 | * buffer that we'll play with. Else we could also do a pthread_once |
| 53 | * or something. |
| 54 | * |
| 55 | * I here the children cry things like: waaayyyy?? Well the reason is to |
| 56 | * avoid a malloc(). This stuff happens quite often. If we can reuse one |
| 57 | * buffer each time, that's fine! The GtkTreeView (if this time that is |
| 58 | * consumer) makes its own copy. Same for any other Gtk+ component that |
| 59 | * accepts strings (like a GtkEntry or a GtkLabel). It will make its own |
| 60 | * copy anyway! If we are going to copy here, that's two copies rather |
| 61 | * than just the one copy in Gtk+ that we have no control over. |
| 62 | **/ |
| 63 | |
| 64 | static gchar readable_date[64]; |
| 65 | |
| 66 | gsize readable_date_size; |
| 67 | int days_now, days_then; |
| 68 | |
| 69 | gmtime_r (&mtime, &file_time); |
| 70 | now = time (NULL); |
| 71 | |
| 72 | /* The idea is that if the amount of days is not the same, we display |
| 73 | * the full date. Else we just display the time. Note that there's a |
| 74 | * hidden bug in this: days_then is the remote timezone, days_now is the |
| 75 | * local timezone. At some point we should fix this! */ |
| 76 | |
| 77 | days_now = now / (24*60*60); |
| 78 | days_then = mtime / (24*60*60); |
| 79 | |
| 80 | /* I think we can fix this using localtime_r */ |
| 81 | |
| 82 | if (days_now == days_then) { |
| 83 | /* Translator: this date-format is the date format for when creating a |
| 84 | * reply of a message if the date is today */ |
| 85 | readable_date_size = strftime (readable_date, 63, _("%X"), &file_time); |
| 86 | } else { |
| 87 | /* Translator: this date-format is the date format for when creating a |
| 88 | * reply of a message if the date is not today */ |
| 89 | readable_date_size = strftime (readable_date, 63, _("%x"), &file_time); |
| 90 | } |
| 91 | |
| 92 | if (readable_date_size > 0) |
| 93 | return readable_date; |
| 94 | |
| 95 | return NULL; |
| 96 | } |
Note: See TracBrowser for help on using the browser.
