#include "prefs_summaries.h"
#include "prefs_themes.h"
#include "prefs_other.h"
+#include "prefs_logging.h"
#include "prefs_send.h"
#include "prefs_wrapping.h"
#include "prefs_compose_writing.h"
#include "imap-thread.h"
#endif
#include "stock_pixmap.h"
-
+#ifdef HAVE_VALGRIND
+#include "valgrind.h"
+#endif
#if USE_OPENSSL
# include "ssl.h"
#endif
#include "timing.h"
+#ifdef MAEMO
+#include <hildon-widgets/hildon-program.h>
+#include <gtk/gtkmain.h>
+#include <libosso.h>
+
+#define OSSO_NAME "claws_mail"
+#define OSSO_SERVICE "com.nokia."OSSO_NAME
+#define OSSO_OBJECT "/com/nokia/"OSSO_NAME
+#define OSSO_IFACE "com.nokia."OSSO_NAME
+
+typedef struct _AppData AppData;
+struct _AppData {
+ HildonProgram *program;
+ HildonWindow *window;
+ osso_context_t *osso_context;
+};
+#endif
+
gchar *prog_version;
gchar *argv0;
static gint lock_socket = -1;
static gint lock_socket_tag = 0;
-
+static gchar *x_display = NULL;
typedef enum
{
ONLINE_MODE_DONT_CHANGE,
}
static MainWindow *static_mainwindow;
+
+#ifdef MAEMO
+static HildonProgram *static_hildonprogram;
+void exit_event_handler(gboolean die_now, gpointer data)
+{
+ AppData *appdata;
+ appdata = (AppData *) data;
+ /* Do whatever application needs to do before exiting */
+ exit_claws(static_mainwindow);
+ hildon_banner_show_information(GTK_WIDGET(appdata->window), NULL,
+ _("Exiting..."));
+
+}
+
+/* Callback for normal D-BUS messages */
+gint dbus_req_handler(const gchar * interface, const gchar * method,
+ GArray * arguments, gpointer data,
+ osso_rpc_t * retval)
+{
+ AppData *appdata;
+ appdata = (AppData *) data;
+
+ osso_system_note_infoprint(appdata->osso_context, method, retval);
+ osso_rpc_free_val(retval);
+
+ return OSSO_OK;
+}
+#endif
static gboolean emergency_exit = FALSE;
#ifdef HAVE_STARTUP_NOTIFICATION
static gboolean sc_exiting = FALSE;
static gboolean sc_starting = FALSE;
+static gboolean show_at_startup = TRUE;
+
+void main_set_show_at_startup(gboolean show)
+{
+ show_at_startup = show;
+}
int main(int argc, char *argv[])
{
+#ifdef MAEMO
+ osso_context_t *osso_context;
+ osso_return_t result;
+#endif
gchar *userrc;
MainWindow *mainwin;
FolderView *folderview;
gtk_set_locale();
gtk_init(&argc, &argv);
+#ifdef MAEMO
+ osso_context = osso_initialize(OSSO_SERVICE, "2.8.1", TRUE, NULL);
+ if (osso_context == NULL) {
+ return OSSO_ERROR;
+ }
+ static_hildonprogram = HILDON_PROGRAM(hildon_program_get_instance());
+#endif
gdk_rgb_init();
gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
gtk_widget_set_default_visual(gdk_rgb_get_visual());
if (rename_force("claws.log", "claws.log.bak") < 0)
FILE_OP_ERROR("claws.log", "rename");
}
- set_log_file("claws.log");
+ set_log_file(LOG_PROTOCOL, "claws.log");
+
+ if (is_file_exist("filtering.log")) {
+ if (rename_force("filtering.log", "filtering.log.bak") < 0)
+ FILE_OP_ERROR("filtering.log", "rename");
+ }
+ set_log_file(LOG_DEBUG_FILTERING, "filtering.log");
CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
prefs_summaries_init();
prefs_message_init();
prefs_other_init();
+ prefs_logging_init();
prefs_receive_init();
prefs_send_init();
#ifdef USE_ASPELL
news_gtk_init();
mainwin = main_window_create();
+#ifdef MAEMO
+ AppData *appdata;
+ appdata = g_new0(AppData, 1);
+ appdata->program = static_hildonprogram;
+ appdata->window = mainwin->window;
+ appdata->osso_context = osso_context;
+ result = osso_rpc_set_cb_f(appdata->osso_context,
+ OSSO_SERVICE,
+ OSSO_OBJECT,
+ OSSO_IFACE,
+ dbus_req_handler, appdata);
+ if (result != OSSO_OK) {
+ return OSSO_ERROR;
+ }
+ /* Add handler for Exit D-BUS messages */
+ result = osso_application_set_exit_cb(appdata->osso_context,
+ exit_event_handler,
+ (gpointer) appdata);
+ if (result != OSSO_OK) {
+ return OSSO_ERROR;
+ }
+#endif
manage_window_focus_in(mainwin->window, NULL, NULL);
folderview = mainwin->folderview;
toolbar_main_set_sensitive(mainwin);
main_window_set_menu_sensitive(mainwin);
- main_window_popup(mainwin);
+ /* if crashed, show window early so that the user
+ * sees what's happening */
+ if (!cmd.crash && crash_file_present)
+ main_window_popup(mainwin);
#ifdef HAVE_LIBETPAN
imap_main_init(prefs_common.skip_ssl_cert_check);
plugin_load_standard_plugins ();
+ /* if not crashed, show window now */
+ if (!(!cmd.crash && crash_file_present)) {
+ /* apart if something told not to show */
+ if (show_at_startup)
+ main_window_popup(mainwin);
+ }
+
if (!folder_have_mailbox()) {
prefs_destroy_cache();
main_window_cursor_normal(mainwin);
if (folder_get_list() != NULL) {
alertpanel_error(_("Claws Mail has detected a configured "
- "mailbox, but is it incomplete. It is "
+ "mailbox, but it is incomplete. It is "
"possibly due to a failing IMAP account. Use "
- "\"Rebuild folder tree\" on the mailbox's folder "
- "to try to fix it."));
+ "\"Rebuild folder tree\" on the mailbox parent "
+ "folder's context menu to try to fix it."));
} else {
alertpanel_error(_("Claws Mail has detected a configured "
"mailbox, but could not load it. It is "
prefs_destroy_cache();
+ compose_reopen_exit_drafts();
+
sc_starting = FALSE;
END_TIMING();
-
+
gtk_main();
+#ifdef MAEMO
+ osso_deinitialize(osso_context);
+#endif
exit_claws(mainwin);
return 0;
main_window_get_size(mainwin);
main_window_get_position(mainwin);
+
prefs_common_write_config();
account_write_config_all();
addressbook_export_to_file();
remove_all_files(get_tmp_dir());
remove_all_files(get_mime_tmp_dir());
- close_log_file();
+ close_log_file(LOG_PROTOCOL);
+ close_log_file(LOG_DEBUG_FILTERING);
#ifdef HAVE_LIBETPAN
imap_main_done();
}
} else if (!strncmp(argv[i], "--attach", 8)) {
const gchar *p = argv[i + 1];
- gchar *file;
+ gchar *file = NULL;
while (p && *p != '\0' && *p != '-') {
if (!cmd.attach_files) {
cmd.attach_files = g_ptr_array_new();
}
- if (*p != G_DIR_SEPARATOR) {
+ if ((file = g_filename_from_uri(p, NULL, NULL)) != NULL) {
+ if (!is_file_exist(file)) {
+ g_free(file);
+ file = NULL;
+ }
+ }
+ if (file == NULL && *p != G_DIR_SEPARATOR) {
file = g_strconcat(claws_get_startup_dir(),
G_DIR_SEPARATOR_S,
p, NULL);
- } else {
+ } else if (file == NULL) {
file = g_strdup(p);
}
g_ptr_array_add(cmd.attach_files, file);
}
}
-static gint get_queued_message_num(void)
-{
- FolderItem *queue;
-
- queue = folder_get_default_queue();
- if (!queue) {
- return -1;
- }
-
- folder_item_scan(queue);
- return queue->total_msgs;
-}
-
static void initial_processing(FolderItem *item, gpointer data)
{
MainWindow *mainwin = (MainWindow *)data;
{
GList *compose_list = NULL;
+ compose_clear_exit_drafts();
while ((compose_list = compose_get_compose_list()) != NULL) {
Compose *c = (Compose*)compose_list->data;
- compose_draft(c);
+ compose_draft(c, COMPOSE_DRAFT_FOR_EXIT);
}
}
gboolean clean_quit(gpointer data)
sc_exiting = TRUE;
debug_print("exiting\n");
if (compose_get_compose_list()) {
- gint val = alertpanel(_("Really quit?"),
- _("Composing message exists."),
- _("_Save to Draft"), _("_Discard them"), _("Do_n't quit"));
- switch (val) {
- case G_ALERTOTHER:
- sc_exiting = FALSE;
- return;
- case G_ALERTALTERNATE:
- break;
- default:
- draft_all_messages();
- }
-
- manage_window_focus_in(mainwin->window, NULL, NULL);
+ draft_all_messages();
}
- if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
+ if (prefs_common.warn_queued_on_exit && procmsg_have_queued_mails_fast()) {
if (alertpanel(_("Queued messages"),
_("Some unsent messages are queued. Exit now?"),
GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL)
!= G_ALERTALTERNATE) {
+ main_window_popup(mainwin);
sc_exiting = FALSE;
return;
}
}
sock_cleanup();
+#ifdef HAVE_VALGRIND
+ if (RUNNING_ON_VALGRIND) {
+ summary_clear_list(mainwin->summaryview);
+ }
+#endif
if (folderview_get_selected_item(mainwin->folderview))
folder_item_close(folderview_get_selected_item(mainwin->folderview));
gtk_main_quit();
path = claws_get_socket_name();
uxsock = fd_connect_unix(path);
+
+ if (x_display == NULL)
+ x_display = g_strdup(g_getenv("DISPLAY"));
+
if (uxsock < 0) {
g_unlink(path);
return fd_open_unix(path);
gchar *str = g_strdup_printf("select %s\n", cmd.target);
fd_write_all(uxsock, str, strlen(str));
g_free(str);
- } else
- fd_write_all(uxsock, "popup\n", 6);
+ } else {
+ gchar buf[BUFSIZ];
+ fd_write_all(uxsock, "get_display\n", 12);
+ memset(buf, 0, sizeof(buf));
+ fd_gets(uxsock, buf, sizeof(buf));
+ if (strcmp2(buf, x_display)) {
+ printf("Claws Mail is already running on display %s.\n",
+ buf);
+ } else {
+ fd_close(uxsock);
+ uxsock = fd_connect_unix(path);
+ fd_write_all(uxsock, "popup\n", 6);
+ }
+ }
fd_close(uxsock);
return -1;
if (!strncmp(buf, "popup", 5)) {
main_window_popup(mainwin);
+ } else if (!strncmp(buf, "get_display", 11)) {
+ fd_write_all(sock, x_display, strlen(x_display));
} else if (!strncmp(buf, "receive_all", 11)) {
inc_all_account_mail(mainwin, FALSE,
prefs_common.newmail_notify_manu);
{
GList *list;
gchar *errstr = NULL;
+ gboolean error = FALSE;
for (list = folder_get_list(); list != NULL; list = list->next) {
Folder *folder = list->data;
if (res) {
folder_item_scan(folder->queue);
}
+
+ if (res < 0)
+ error = TRUE;
}
}
if (errstr) {
g_free(errstr);
alertpanel_error_log(tmp);
g_free(tmp);
- } else {
+ } else if (error) {
alertpanel_error_log("Some errors occurred "
"while sending queued messages.");
}
sigprocmask(SIG_UNBLOCK, &mask, 0);
#endif /* !G_OS_WIN32 */
}
+
+#ifdef MAEMO
+HildonProgram *hildon_program()
+{
+ return static_hildonprogram;
+}
+#endif