Implement "search messages" action (fixes NB#57209).
[modest] / src / gnome / modest-platform.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <libgnomevfs/gnome-vfs-mime.h>
31 #include <libgnomeui/gnome-icon-lookup.h>
32 #include <tny-gnome-device.h>
33
34 #include "modest-platform.h"
35 #include "modest-mail-operation-queue.h"
36 #include "modest-runtime.h"
37 #include "gnome/modest-gnome-global-settings-dialog.h"
38
39 gboolean
40 modest_platform_init (void)
41 {       
42         return TRUE; /* nothing to do */
43 }
44
45
46 TnyDevice*
47 modest_platform_get_new_device (void)
48 {
49         return TNY_DEVICE (tny_gnome_device_new ());
50 }
51
52
53 gchar*
54 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
55                                           gchar **effective_mime_type)
56 {
57         GString *mime_str = NULL;
58         gchar *icon_name  = NULL;
59         gchar *uri;
60         const static gchar* octet_stream = "application/octet-stream";
61         
62         g_return_val_if_fail (name || mime_type, NULL);
63
64         if (!mime_type || g_ascii_strcasecmp (mime_type, octet_stream)) 
65                 mime_str = g_string_new(gnome_vfs_mime_type_from_name_or_default
66                                         (name, "application/octet-stream"));
67         else {
68                 mime_str = g_string_new (mime_type);
69                 g_string_ascii_down (mime_str);
70         }
71
72         uri = g_strconcat ("file:///", name ? name : "dummy", NULL);
73         icon_name  = gnome_icon_lookup (gtk_icon_theme_get_default(), NULL,
74                                         uri, NULL, NULL, mime_str->str, 0, 0);
75         g_free (uri);
76
77         if (effective_mime_type)
78                 *effective_mime_type = g_string_free (mime_str, FALSE);
79         else
80                 g_string_free (mime_str, TRUE);
81
82         return icon_name;
83 }
84
85 gboolean 
86 modest_platform_activate_uri (const gchar *uri)
87 {
88         modest_runtime_not_implemented (NULL);
89         return FALSE;
90 }
91
92 gboolean 
93 modest_platform_activate_file (const gchar *path, const gchar *mime_type)
94 {
95         modest_runtime_not_implemented (NULL);
96         return FALSE;
97 }
98
99 gboolean 
100 modest_platform_show_uri_popup (const gchar *uri)
101 {
102         modest_runtime_not_implemented (NULL);
103         return FALSE;
104 }
105
106 GdkPixbuf*
107 modest_platform_get_icon (const gchar *name)
108 {
109         GError *err = NULL;
110         GdkPixbuf* pixbuf;
111
112         g_return_val_if_fail (name, NULL);
113
114         pixbuf = gdk_pixbuf_new_from_file (name, &err);
115
116         if (!pixbuf) {
117                 g_printerr ("modest: error while loading icon '%s': %s\n",
118                             name, err->message);
119                 g_error_free (err);
120         }
121         
122         return pixbuf;
123 }
124
125
126 const gchar*
127 modest_platform_get_app_name (void)
128 {
129         return ("Modest");
130 }
131
132 gint 
133 modest_platform_run_new_folder_dialog (GtkWindow *parent_window,
134                                        TnyFolderStore *parent_folder,
135                                        gchar *suggested_name,
136                                        gchar **folder_name)
137 {
138         GtkWidget *dialog, *entry;
139         gint result;
140
141         /* Ask the user for the folder name */
142         dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
143                                               parent_window,
144                                               GTK_DIALOG_MODAL,
145                                               GTK_STOCK_CANCEL,
146                                               GTK_RESPONSE_REJECT,
147                                               GTK_STOCK_OK,
148                                               GTK_RESPONSE_ACCEPT,
149                                               NULL);
150         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
151                             gtk_label_new (_("Please enter a name for the new folder")),
152                             FALSE, FALSE, 0);
153                 
154         entry = gtk_entry_new_with_max_length (40);
155         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
156                             entry,
157                             TRUE, FALSE, 0);
158         
159         gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
160
161         result = gtk_dialog_run (GTK_DIALOG(dialog));
162         if (result == GTK_RESPONSE_ACCEPT)
163                 *folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
164
165         gtk_widget_destroy (dialog);
166
167         return result;
168 }
169
170
171 gint
172 modest_platform_run_confirmation_dialog (GtkWindow *parent_window,
173                                          const gchar *msg)
174 {
175         /* TODO implement confirmation dialog */
176         return GTK_RESPONSE_CANCEL;
177 }
178
179 void
180 modest_platform_run_information_dialog (GtkWindow *parent_window,
181                                         const gchar *message)
182 {
183         /* TODO: implement a information dialog */
184 }
185
186 gboolean modest_platform_connect_and_wait (GtkWindow *parent_window)
187 {
188         /* TODO: Do something with network-manager? 
189            Otherwise, maybe it is safe to assume that we would already be online if we could be. */
190         return TRUE;
191 }
192
193 gboolean modest_platform_set_update_interval (guint minutes)
194 {
195         /* TODO. */
196         return FALSE;
197 }
198
199 void
200 modest_platform_run_sort_dialog (GtkWindow *parent_window,
201                                  ModestSortDialogType type)
202 {
203         /* TODO */
204 }
205
206 GtkWidget *
207 modest_platform_get_global_settings_dialog ()
208 {
209         return modest_gnome_global_settings_dialog_new ();
210 }
211
212 void 
213 modest_platform_on_new_msg (void)
214 {
215         /* TODO: implement this */
216         g_print ("--------------- NEW MESSAGE ARRIVED ---------------\n");
217 }
218
219
220
221 gboolean
222 modest_platform_show_help (GtkWidget *widget, const gchar *help_id)
223 {
224         return TRUE; /* TODO */
225 }
226
227 void
228 modest_platform_show_search_messages (GtkWindow *parent_window)
229 {
230         modest_runtime_not_implemented (NULL);
231 }