From 6b2af6b8b67b7d0abc2d19a89c895f64239487f3 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 10 May 2007 03:48:56 +0000 Subject: implemented '--open' command line option which open messages specified with command-line in new window. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1686 ee746299-78ed-0310-b773-934348b2243d --- src/main.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 1ad4cf1f..649d79f1 100644 --- a/src/main.c +++ b/src/main.c @@ -114,6 +114,7 @@ static struct RemoteCmd { gboolean status_full; GPtrArray *status_folders; GPtrArray *status_full_folders; + gchar *open_msg; gboolean configdir; gboolean exit; #ifdef G_OS_WIN32 @@ -470,6 +471,14 @@ static void parse_cmd_opt(int argc, char *argv[]) i++; p = argv[i + 1]; } + } else if (!strncmp(argv[i], "--open", 6)) { + const gchar *p = argv[i + 1]; + + if (p && *p != '\0' && *p != '-') { + cmd.open_msg = g_locale_to_utf8 + (p, -1, NULL, NULL, NULL); + i++; + } } else if (!strncmp(argv[i], "--configdir", 11)) { const gchar *p = argv[i + 1]; @@ -1112,6 +1121,12 @@ static gint prohibit_duplicate_launch(void) if (!strncmp(buf, ".\n", 2)) break; fputs(buf, stdout); } + } else if (cmd.open_msg) { + gchar *str; + + str = g_strdup_printf("open %s\n", cmd.open_msg); + fd_write_all(sock, str, strlen(str)); + g_free(str); } else if (cmd.exit) { fd_write_all(sock, "exit\n", 5); } else { @@ -1237,6 +1252,37 @@ static gboolean lock_socket_input_cb(GIOChannel *source, GIOCondition condition, fd_write_all(sock, ".\n", 2); g_free(status); if (folders) g_ptr_array_free(folders, TRUE); + } else if (!strncmp(buf, "open", 4)) { + gchar *path; + gchar *id; + gchar *msg; + gint num; + FolderItem *item; + MsgInfo *msginfo; + MessageView *msgview; + + strretchomp(buf); + if (strlen(buf) < 6 || buf[4] != ' ') { + fd_close(sock); + return TRUE; + } + + path = buf + 5; + id = g_path_get_dirname(path); + msg = g_path_get_basename(path); + num = to_number(msg); + item = folder_find_item_from_identifier(id); + debug_print("open folder id: %s (msg %d)\n", id, num); + if (num > 0 && item) { + msginfo = folder_item_get_msginfo(item, num); + if (msginfo) { + msgview = messageview_create_with_new_window(); + messageview_show(msgview, msginfo, FALSE); + } else + debug_print("message %d not found\n", num); + } + g_free(msg); + g_free(id); } else if (!strncmp(buf, "exit", 4)) { fd_close(sock); app_will_exit(TRUE); -- cgit v1.2.3