From 559296a3a77a286bed2ba6e861ff39dbfe81dfda Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 19 May 2022 07:36:21 +0300 Subject: [PATCH] toys: remove The didn't work for quite some time, and would need quite a few updates to even compile with the latest. So remove. --- Makefile.am | 2 +- NEWS.org | 4 +- configure.ac | 54 +--- meson.build | 11 - meson_options.txt | 7 +- toys/Makefile.am | 24 -- toys/msg2pdf/Makefile.am | 53 ---- toys/msg2pdf/msg2pdf.c | 315 ----------------------- toys/mug/Makefile.am | 93 ------- toys/mug/mu-msg-attach-view.cc | 291 ---------------------- toys/mug/mu-msg-attach-view.hh | 69 ----- toys/mug/mu-msg-body-view.cc | 334 ------------------------- toys/mug/mu-msg-body-view.hh | 71 ------ toys/mug/mu-msg-header-view.cc | 180 -------------- toys/mug/mu-msg-header-view.hh | 69 ----- toys/mug/mu-msg-view.cc | 224 ----------------- toys/mug/mu-msg-view.hh | 68 ----- toys/mug/mu-widget-util.c | 94 ------- toys/mug/mu-widget-util.h | 42 ---- toys/mug/mug-msg-list-view.cc | 430 -------------------------------- toys/mug/mug-msg-list-view.h | 82 ------ toys/mug/mug-msg-view.cc | 148 ----------- toys/mug/mug-msg-view.h | 58 ----- toys/mug/mug-query-bar.c | 112 --------- toys/mug/mug-query-bar.h | 52 ---- toys/mug/mug-shortcuts.cc | 148 ----------- toys/mug/mug-shortcuts.h | 68 ----- toys/mug/mug.cc | 401 ----------------------------- toys/mug/mug.svg | 443 --------------------------------- 29 files changed, 5 insertions(+), 3942 deletions(-) delete mode 100644 toys/Makefile.am delete mode 100644 toys/msg2pdf/Makefile.am delete mode 100644 toys/msg2pdf/msg2pdf.c delete mode 100644 toys/mug/Makefile.am delete mode 100644 toys/mug/mu-msg-attach-view.cc delete mode 100644 toys/mug/mu-msg-attach-view.hh delete mode 100644 toys/mug/mu-msg-body-view.cc delete mode 100644 toys/mug/mu-msg-body-view.hh delete mode 100644 toys/mug/mu-msg-header-view.cc delete mode 100644 toys/mug/mu-msg-header-view.hh delete mode 100644 toys/mug/mu-msg-view.cc delete mode 100644 toys/mug/mu-msg-view.hh delete mode 100644 toys/mug/mu-widget-util.c delete mode 100644 toys/mug/mu-widget-util.h delete mode 100644 toys/mug/mug-msg-list-view.cc delete mode 100644 toys/mug/mug-msg-list-view.h delete mode 100644 toys/mug/mug-msg-view.cc delete mode 100644 toys/mug/mug-msg-view.h delete mode 100644 toys/mug/mug-query-bar.c delete mode 100644 toys/mug/mug-query-bar.h delete mode 100644 toys/mug/mug-shortcuts.cc delete mode 100644 toys/mug/mug-shortcuts.h delete mode 100644 toys/mug/mug.cc delete mode 100644 toys/mug/mug.svg diff --git a/Makefile.am b/Makefile.am index 25828a49..04fa45b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,7 +28,7 @@ else mu4e= endif -SUBDIRS=m4 man lib $(guile) mu $(mu4e) contrib toys +SUBDIRS=m4 man lib $(guile) mu $(mu4e) contrib ACLOCAL_AMFLAGS=-I m4 diff --git a/NEWS.org b/NEWS.org index d9da4f7b..75a1b84b 100644 --- a/NEWS.org +++ b/NEWS.org @@ -172,8 +172,8 @@ *** toys - - the ~mug~ toys is deprecated and to be removed after 1.8 - + - the ~toys~ (~mug~) has been removed, as they no longer worked with the rest of + the code. * 1.6 (released, as of July 27 2021) diff --git a/configure.ac b/configure.ac index 7cf3416d..098ac550 100644 --- a/configure.ac +++ b/configure.ac @@ -16,7 +16,7 @@ AC_PREREQ([2.68]) AC_INIT([mu],[1.7.21],[https://github.com/djcb/mu/issues],[mu]) -AC_COPYRIGHT([Copyright (C) 2008-2021 Dirk-Jan C. Binnema]) +AC_COPYRIGHT([Copyright (C) 2008-2022 Dirk-Jan C. Binnema]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_SRCDIR([mu/mu.cc]) # libtoolize wants to put some stuff in here; if you have an old @@ -193,30 +193,6 @@ PKG_CHECK_MODULES(XAPIAN,xapian-core >= 1.4,[ AC_DEFINE(MU_STORE_SCHEMA_VERSION,["462"],['Schema' version of the database]) ############################################################################### -############################################################################### -# we need GTK+3 for some of the graphical tools -# use --without-gtk to disable it -AC_ARG_ENABLE([gtk],AS_HELP_STRING([--disable-gtk],[Disable GTK+])) -AS_IF([test "x$enable_gtk" != "xno"],[ - PKG_CHECK_MODULES(GTK,gtk+-3.0,[have_gtk=yes],[have_gtk=no]) - gtk_version="$($PKG_CONFIG --modversion gtk+-3.0)" -]) -AM_CONDITIONAL(HAVE_GTK,[test "x$have_gtk" = "xyes"]) - -# webkit? needed for the fancy web widget -# use --disable-webkit to disable it, even if you have it -# -# and note this is just a toy, not for distribution. -AC_ARG_ENABLE([webkit],AS_HELP_STRING([--disable-webkit],[Disable webkit])) -AS_IF([test "x$enable_webkit" != "xno"],[ - PKG_CHECK_MODULES(WEBKIT,webkit2gtk-4.0 >= 2.0, [have_webkit=yes],[have_webkit=no]) - AS_IF([test "x$have_webkit" = "xyes"],[ - webkit_version="$($PKG_CONFIG --modversion webkit2gtk-4.0)"]) -]) -AM_CONDITIONAL(HAVE_WEBKIT, [test "x$have_webkit" = "xyes"]) -AM_CONDITIONAL(BUILD_GUI,[test "x$have_webkit" = "xyes" -a "x$have_gtk" = "xyes"]) -############################################################################### - ################################################################################ # should we try to build an emacs dynamic module? #AC_CHECK_HEADER([emacs-module.h],[ @@ -285,8 +261,6 @@ guile/Makefile guile/mu/Makefile guile/examples/Makefile guile/scripts/Makefile -toys/Makefile -toys/mug/Makefile man/Makefile m4/Makefile contrib/Makefile @@ -307,30 +281,10 @@ echo "Xapian version : $xapian_version" echo "GLib version : $glib_version" echo "GMime version : $gmime_version" -AM_COND_IF([BUILD_GUI],[ -echo "GTK+ version : $gtk_version" -echo "Webkit2/GTK+ version : $webkit_version" -]) - AM_COND_IF([BUILD_GUILE],[ echo "Guile version : $guile_version" ]) - -AS_IF([test "x$build_mu4e" = "xyes"],[ -echo "Build mu4e : yes" -echo "Emacs version : $emacs_version" -#AM_COND_IF([BUILD_EMACS_MODULE],[ -#echo "Build emacs module : yes"],[ -#echo "Build emacs module : no" -#])]) - -AM_COND_IF([BUILD_GUI],[ -echo "Build 'mug' toy-ui (gtk+/webkit) : yes"],[ -echo "Build 'mug' toy-ui (gtk+/webkit) : no" -]) - echo - echo "Have direntry->d_ino : $use_dirent_d_ino" echo "Have direntry->d_type : $use_dirent_d_type" echo "------------------------------------------------" @@ -348,12 +302,6 @@ if test "x$have_makeinfo" != "xyes"; then echo fi -# gui -AS_IF([test "x$buildgui" = "xyes"],[ - echo "* The demo UI will be built in toys/mug" - echo -]) - # wordexp AS_IF([test "x$ac_cv_header_wordexp_h" != "xyes"],[ echo "* Your system does not seem to have the 'wordexp' function." diff --git a/meson.build b/meson.build index 6f94b7a6..cf4e9a6d 100644 --- a/meson.build +++ b/meson.build @@ -121,11 +121,6 @@ thread_dep = dependency('threads') # soft dependencies guile_dep = dependency('guile-3.0', required: get_option('guile')) -if get_option('toys').enabled() - gtk_dep = dependency('gtk+-3.0') - webkit_dep = dependency('webkit2gtk-4.0') -endif - awk=find_program(['gawk', 'awk']) # soft dependencies @@ -190,12 +185,6 @@ if not get_option('guile').disabled() and guile_dep.found() endif config_h_data.set_quoted('MU_PROGRAM', mu.full_path()) - - -if get_option('toys').enabled() - message('toys are disabled for now') - #subdir('toys/mug') -endif ################################################################################ ################################################################################ diff --git a/meson_options.txt b/meson_options.txt index 0c70826e..df75223a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,4 @@ -## Copyright (C) 2021 Dirk-Jan C. Binnema +## Copyright (C) 2022 Dirk-Jan C. Binnema ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -20,11 +20,6 @@ option('guile', value: 'auto', description: 'build the guile scripting support (requires guile-3.x)') -option('toys', - type : 'feature', - value: 'auto', - description: 'build various toy programs (requires gtk3/gtk-webkit)') - option('readline', type: 'feature', value: 'auto', diff --git a/toys/Makefile.am b/toys/Makefile.am deleted file mode 100644 index 7c84ce91..00000000 --- a/toys/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -## Copyright (C) 2008-2020 Dirk-Jan C. Binnema -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software Foundation, -## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -include $(top_srcdir)/gtest.mk - -SUBDIRS= - -# for mug2 and msg2pdf, we need webkit -if BUILD_GUI -#SUBDIRS += mug # msg2pdf -endif diff --git a/toys/msg2pdf/Makefile.am b/toys/msg2pdf/Makefile.am deleted file mode 100644 index 279c22c2..00000000 --- a/toys/msg2pdf/Makefile.am +++ /dev/null @@ -1,53 +0,0 @@ -## Copyright (C) 2012-2013 Dirk-Jan C. Binnema -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 3 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software Foundation, -## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -include $(top_srcdir)/gtest.mk - -# enforce compiling this dir first before descending into tests/ -SUBDIRS= . - -AM_CPPFLAGS=-I${top_srcdir}/lib $(GTK_CFLAGS) $(WEBKIT_CFLAGS) - -# don't use -Werror, as it might break on other compilers -# use -Wno-unused-parameters, because some callbacks may not -# really need all the params they get -AM_CFLAGS=$(ASAN_CFLAGS) -Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement - -noinst_PROGRAMS= \ - msg2pdf - -# note, mug.cc is '.cc' only because libmu must explicitly -# be linked as c++, not c. -msg2pdf_SOURCES= \ - msg2pdf.c \ - dummy.cc - -# we need to use dummy.cc to enforce c++ linking... -BUILT_SOURCES= \ - dummy.cc - -dummy.cc: - touch dummy.cc - -DISTCLEANFILES= \ - $(BUILT_SOURCES) - - -msg2pdf_LDADD= \ - $(ASAN_LDFLAGS) \ - ${top_builddir}/lib/libmu.la \ - $(GTK_LIBS) \ - ${WEBKIT_LIBS} diff --git a/toys/msg2pdf/msg2pdf.c b/toys/msg2pdf/msg2pdf.c deleted file mode 100644 index 1faf2fe1..00000000 --- a/toys/msg2pdf/msg2pdf.c +++ /dev/null @@ -1,315 +0,0 @@ -/* -** Copyright (C) 2012-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#include -#include -#include - -#include -#include -#include -#include -#include - -typedef enum { UNKNOWN, OK, FAILED } Result; - -static void -on_failed (WebKitPrintOperation *print_operation, - GError *error, - Result *result) -{ - if (error) - g_warning ("%s", error->message); - - *result = FAILED; -} - - -static void -on_finished (WebKitPrintOperation *print_operation, - Result *result) -{ - if (*result == UNKNOWN) - *result = OK; -} - - -static gboolean -print_to_pdf (GtkWidget *webview, GError **err) -{ - GtkWidget *win; - WebKitPrintOperation *op; - GtkPrintSettings *settings; - char *path, *uri; - Result res; - time_t started; - const int max_time = 3; /* max 3 seconds to download stuff */ - - - path = g_strdup_printf ("%s%c%x.pdf", mu_util_cache_dir(), - G_DIR_SEPARATOR, (unsigned)random()); - if (!mu_util_create_dir_maybe (mu_util_cache_dir(), 0700, FALSE)) { - g_warning ("Couldn't create tempdir"); - g_free (path); - return FALSE; - } - uri = g_filename_to_uri (path, NULL, NULL); - g_print ("%s\n", path); - g_free(path); - if (!uri) { - g_warning ("failed to create uri"); - return FALSE; - } - - win = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_container_add(GTK_CONTAINER(win), webview); - gtk_widget_show_all(win); - - - op = webkit_print_operation_new (WEBKIT_WEB_VIEW(webview)); - settings = gtk_print_settings_new(); - gtk_print_settings_set(settings, - GTK_PRINT_SETTINGS_OUTPUT_URI, uri); - gtk_print_settings_set(settings, - GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "PDF"); - g_free(uri); - - webkit_print_operation_set_print_settings(op, settings); - - - webkit_print_operation_run_dialog(op, NULL); - - - res = UNKNOWN; - g_signal_connect(op, "failed", G_CALLBACK(on_failed), &res); - g_signal_connect(op, "finished", G_CALLBACK(on_finished), &res); - - webkit_print_operation_print(op); - started = time (NULL); - do { - gtk_main_iteration_do (FALSE); - } while (res == UNKNOWN /*&& (time(NULL) - started) <= max_time*/); - - g_object_unref (op); - - return res == OK; -} - - -static char* -save_file_for_cid (MuMsg *msg, const char* cid) -{ - gint idx; - gchar *filepath; - GError *err; - - g_return_val_if_fail (msg, NULL); - g_return_val_if_fail (cid, NULL); - - idx = mu_msg_find_index_for_cid (msg, MU_MSG_OPTION_NONE, cid); - if (idx < 0) { - g_warning ("%s: cannot find %s", __func__, cid); - return NULL; - } - - err = NULL; - filepath = mu_msg_part_get_cache_path (msg, MU_MSG_OPTION_NONE, idx, NULL); - if (!filepath) - goto errexit; - - if (!mu_msg_part_save (msg, MU_MSG_OPTION_USE_EXISTING, filepath, idx, - &err)) - goto errexit; - - return filepath; - -errexit: - g_warning ("%s: failed to save %s: %s", __func__, - filepath, - err&&err->message?err->message:"error"); - g_clear_error (&err); - g_free (filepath); - - return NULL; -} - -static void -on_resource_load_started (WebKitWebView *self, - WebKitWebResource *resource, - WebKitURIRequest *request, - MuMsg *msg) -{ - const char* uri; - - uri = webkit_uri_request_get_uri (request); - - if (g_ascii_strncasecmp (uri, "cid:", 4) == 0) { - gchar *filepath; - filepath = save_file_for_cid (msg, uri); - if (filepath) { - gchar *fileuri; - fileuri = g_strdup_printf ("file://%s", filepath); - webkit_uri_request_set_uri (request, fileuri); - g_debug("printing %s", fileuri); - g_free (fileuri); - g_free (filepath); - } - } -} - - -/* return the path to the output file, or NULL in case of error */ -static gboolean -generate_pdf (MuMsg *msg, const char *str, GError **err) -{ - GtkWidget *view; - WebKitSettings *settings; - time_t started; - gboolean loading; - const int max_time = 3; /* max 3 seconds to download stuff */ - - settings = webkit_settings_new (); - g_object_set (G_OBJECT(settings), - "enable-javascript", FALSE, - "auto-load-images", TRUE, - "enable-plugins", FALSE, - NULL); - - view = webkit_web_view_new (); - - /* to support cid: */ - g_signal_connect (G_OBJECT(view), "resource-load-started", - G_CALLBACK (on_resource_load_started), msg); - - webkit_web_view_set_settings (WEBKIT_WEB_VIEW(view), settings); - webkit_web_view_load_html (WEBKIT_WEB_VIEW(view), str, NULL); - g_object_unref (settings); - - started = time (NULL); - do { - loading = webkit_web_view_is_loading (WEBKIT_WEB_VIEW(view)); - gtk_main_iteration_do (FALSE); - } while (loading && (time(NULL) - started) <= max_time); - - return print_to_pdf (view, err); -} - -static void -add_header (GString *gstr, const char* header, const char *val) -{ - char *esc; - - if (!val) - return; - - esc = g_markup_escape_text (val, -1); - g_string_append_printf (gstr, "%s: %s
", header, esc); - g_free (esc); -} - - /* return the path to the output file, or NULL in case of error */ -static gboolean -convert_to_pdf (MuMsg *msg, GError **err) -{ - GString *gstr; - const char *body; - gchar *data; - gboolean rv; - - gstr = g_string_sized_new (4096); - - add_header (gstr, "From", mu_msg_get_from (msg)); - add_header (gstr, "To", mu_msg_get_to (msg)); - add_header (gstr, "Cc", mu_msg_get_cc (msg)); - add_header (gstr, "Subject", mu_msg_get_subject (msg)); - add_header (gstr, "Date", mu_date_str_s - ("%c", mu_msg_get_date(msg))); - - gstr = g_string_append (gstr, "
\n"); - - body = mu_msg_get_body_html (msg, MU_MSG_OPTION_NONE); - if (body) - g_string_append_printf (gstr, "%s", body); - else { - body = mu_msg_get_body_text (msg, MU_MSG_OPTION_NONE); - if (body) { - gchar *esc; - esc = g_markup_escape_text (body, -1); - g_string_append_printf (gstr, "
\n%s\n
", - esc); - g_free (esc); - } else - gstr = g_string_append - (gstr, "No body\n"); - } - - data = g_string_free (gstr, FALSE); - rv = generate_pdf (msg, data, err); - g_free (data); - - return rv; -} - - -int -main(int argc, char *argv[]) -{ - MuMsg *msg; - GError *err; - - if (argc != 2) { - g_print ("msg2pdf: generate pdf files from e-mail messages\n" - "usage: msg2pdf \n"); - return 1; - } - - gtk_init (&argc, &argv); - - if (access (argv[1], R_OK) != 0) { - g_printerr ("%s is not a readable file\n", argv[1]); - return 1; - } - - err = NULL; - msg = mu_msg_new_from_file (argv[1], NULL, &err); - if (!msg) { - g_printerr ("failed to create msg for %s\n", argv[1]); - goto err; - } - - if (!convert_to_pdf (msg, &err)) { - g_printerr ("failed to create pdf from %s\n", argv[1]); - goto err; - } - - /* it worked! */ - mu_msg_unref (msg); - return 0; - -err: - /* some error occurred */ - mu_msg_unref (msg); - - if (err) - g_printerr ("error: %s", err->message); - - g_clear_error (&err); - return 1; - -} diff --git a/toys/mug/Makefile.am b/toys/mug/Makefile.am deleted file mode 100644 index 43c225b0..00000000 --- a/toys/mug/Makefile.am +++ /dev/null @@ -1,93 +0,0 @@ -## Copyright (C) 2008-2020 Dirk-Jan C. Binnema -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## t he Free Software Foundation; either version 3 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software Foundation, -## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -include $(top_srcdir)/gtest.mk - -# enforce compiling this dir first before descending into tests/ -SUBDIRS= . - -AM_CPPFLAGS=-I${top_srcdir} -I${top_srcdir}/lib $(GTK_CFLAGS) $(WEBKIT_CFLAGS) \ - -DICONDIR='"$(icondir)"' -DMUGDIR='"$(abs_srcdir)"' \ - -DGSEAL_ENABLE - -# remove -DGTK_DISABLE_DEPRECATED for now, since it breaks 3.10+ compilation - -# don't use -Werror, as it might break on other compilers -# use -Wno-unused-parameters, because some callbacks may not -# really need all the params they get -AM_CFLAGS= \ - $(WARN_CFLAGS) \ - $(ASAN_CFLAGS) \ - -Wno-redundant-decls \ - -Wno-deprecated-declarations \ - -Wno-switch-enum - -AM_CXXFLAGS= \ - $(WARN_CXXFLAGS) \ - $(ASAN_CFLAGS) \ - -Wno-redundant-decls \ - -Wno-deprecated-declarations \ - -Wno-switch-enum -# -# Distributors: this is a _toy_, not for distribution. the "noinst_" says enough -# -noinst_PROGRAMS= \ - mug - -mug_SOURCES= \ - mug.cc \ - mug-msg-list-view.cc \ - mug-msg-list-view.h \ - mug-msg-view.h \ - mug-msg-view.cc \ - mug-query-bar.h \ - mug-query-bar.c \ - mug-shortcuts.cc \ - mug-shortcuts.h - -DISTCLEANFILES= \ - $(BUILT_SOURCES) - -mug_LDADD= \ - $(ASAN_LDFLAGS) \ - ${top_builddir}/lib/libmu.la \ - ${top_builddir}/lib/utils/libmu-utils.la \ - libmuwidgets.la \ - ${GTK_LIBS} - -noinst_LTLIBRARIES= \ - libmuwidgets.la - -libmuwidgets_la_SOURCES= \ - mu-widget-util.h \ - mu-widget-util.c \ - mu-msg-attach-view.cc \ - mu-msg-attach-view.hh \ - mu-msg-body-view.cc \ - mu-msg-body-view.hh \ - mu-msg-header-view.cc \ - mu-msg-header-view.hh \ - mu-msg-view.hh \ - mu-msg-view.cc - -libmuwidgets_la_LIBADD= \ - ${top_builddir}/lib/libmu.la \ - ${GTK_LIBS} \ - ${WEBKIT_LIBS} \ - ${GIO_LIBS} - -EXTRA_DIST= \ - mug.svg diff --git a/toys/mug/mu-msg-attach-view.cc b/toys/mug/mu-msg-attach-view.cc deleted file mode 100644 index 82a7ae7b..00000000 --- a/toys/mug/mu-msg-attach-view.cc +++ /dev/null @@ -1,291 +0,0 @@ -/* -** Copyright (C) 2011-2021 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#include "mu-msg-attach-view.hh" -#include "mu-widget-util.h" -#include -#include - -using namespace Mu; - -enum { - ICON_COL, - NAME_COL, - PARTNUM_COL, - - NUM_COL -}; - -/* 'private'/'protected' functions */ -static void mu_msg_attach_view_class_init(MuMsgAttachViewClass* klass); -static void mu_msg_attach_view_init(MuMsgAttachView* obj); -static void mu_msg_attach_view_finalize(GObject* obj); - -/* list my signals */ -enum { - ATTACH_ACTIVATED, - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - -struct _MuMsgAttachViewPrivate { - MuMsg* _msg; -}; -#define MU_MSG_ATTACH_VIEW_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MU_TYPE_MSG_ATTACH_VIEW, MuMsgAttachViewPrivate)) -/* globals */ -static GtkIconViewClass* parent_class = NULL; - -static guint signals[LAST_SIGNAL] = {0}; - -G_DEFINE_TYPE(MuMsgAttachView, mu_msg_attach_view, GTK_TYPE_ICON_VIEW); - -static void -set_message(MuMsgAttachView* self, MuMsg* msg) -{ - if (self->_priv->_msg == msg) - return; /* nothing to todo */ - - if (self->_priv->_msg) { - mu_msg_unref(self->_priv->_msg); - self->_priv->_msg = NULL; - } - - if (msg) - self->_priv->_msg = mu_msg_ref(msg); -} - -static void -mu_msg_attach_view_class_init(MuMsgAttachViewClass* klass) -{ - GObjectClass* gobject_class; - gobject_class = (GObjectClass*)klass; - - parent_class = (GtkIconViewClass*)g_type_class_peek_parent(klass); - gobject_class->finalize = mu_msg_attach_view_finalize; - - g_type_class_add_private(gobject_class, sizeof(MuMsgAttachViewPrivate)); - - signals[ATTACH_ACTIVATED] = - g_signal_new("attach-activated", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(MuMsgAttachViewClass, attach_activated), - NULL, - NULL, - g_cclosure_marshal_VOID__UINT_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_UINT, - G_TYPE_POINTER); -} - -static void -item_activated(MuMsgAttachView* self, GtkTreePath* tpath) -{ - GtkTreeModel* model; - GtkTreeIter iter; - guint partnum; - - model = gtk_icon_view_get_model(GTK_ICON_VIEW(self)); - if (!gtk_tree_model_get_iter(model, &iter, tpath)) { - g_warning("could not find path"); - } - - gtk_tree_model_get(model, &iter, PARTNUM_COL, &partnum, -1); - - g_signal_emit(G_OBJECT(self), signals[ATTACH_ACTIVATED], 0, partnum, self->_priv->_msg); -} - -static void -accumulate_parts(MuMsgAttachView* self, GtkTreePath* path, GSList** lst) -{ - GtkTreeIter iter; - GtkTreeModel* model; - - /* don't unref */ - model = gtk_icon_view_get_model(GTK_ICON_VIEW(self)); - - if (gtk_tree_model_get_iter(model, &iter, path)) { - gchar* filepath; - gint idx; - gtk_tree_model_get(model, &iter, PARTNUM_COL, &idx, -1); - filepath = - mu_msg_part_get_cache_path(self->_priv->_msg, MU_MSG_OPTION_NONE, idx, NULL); - if (filepath) { - if (mu_msg_part_save(self->_priv->_msg, - MU_MSG_OPTION_USE_EXISTING, - filepath, - idx, - NULL)) { - GFile* file; - file = g_file_new_for_path(filepath); - *lst = g_slist_prepend(*lst, g_file_get_uri(file)); - g_object_unref(file); - } else - g_warning("error saving msg part"); - g_free(filepath); - } - } -} - -static void -on_drag_data_get(MuMsgAttachView* self, - GdkDragContext* drag_context, - GtkSelectionData* data, - guint info, - guint time, - gpointer user_data) -{ - GSList *lst, *cur; - char** uris; - int i; - - lst = NULL; - gtk_icon_view_selected_foreach(GTK_ICON_VIEW(self), - (GtkIconViewForeachFunc)accumulate_parts, - &lst); - - uris = g_new(char*, g_slist_length(lst) + 1); - for (cur = lst, i = 0; cur; cur = g_slist_next(cur)) - uris[i++] = (gchar*)cur->data; - - uris[i] = NULL; - gtk_selection_data_set_uris(data, uris); - - g_free(uris); - g_slist_free_full(lst, g_free); -} - -static void -mu_msg_attach_view_init(MuMsgAttachView* obj) -{ - GtkListStore* store; - - obj->_priv = MU_MSG_ATTACH_VIEW_GET_PRIVATE(obj); - obj->_priv->_msg = NULL; - - store = gtk_list_store_new(NUM_COL, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT); - gtk_icon_view_set_model(GTK_ICON_VIEW(obj), GTK_TREE_MODEL(store)); - g_object_unref(store); - - gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(obj), ICON_COL); - gtk_icon_view_set_text_column(GTK_ICON_VIEW(obj), NAME_COL); - - gtk_icon_view_set_margin(GTK_ICON_VIEW(obj), 0); - gtk_icon_view_set_spacing(GTK_ICON_VIEW(obj), 0); - gtk_icon_view_set_item_padding(GTK_ICON_VIEW(obj), 0); - - /* note: only since GTK+ 2.22 */ - /* gtk_icon_view_set_item_orientation (GTK_ICON_VIEW(obj), */ - /* GTK_ORIENTATION_HORIZONTAL); */ - - g_signal_connect(G_OBJECT(obj), "item-activated", G_CALLBACK(item_activated), NULL); - - gtk_icon_view_set_selection_mode(GTK_ICON_VIEW(obj), GTK_SELECTION_MULTIPLE); - /* drag & drop */ - gtk_icon_view_enable_model_drag_source(GTK_ICON_VIEW(obj), - (GdkModifierType)0, - NULL, - 0, - GDK_ACTION_COPY); - gtk_drag_source_add_uri_targets(GTK_WIDGET(obj)); - g_signal_connect(obj, "drag-data-get", G_CALLBACK(on_drag_data_get), NULL); -} - -static void -mu_msg_attach_view_finalize(GObject* obj) -{ - set_message(MU_MSG_ATTACH_VIEW(obj), NULL); - - G_OBJECT_CLASS(parent_class)->finalize(obj); -} - -GtkWidget* -mu_msg_attach_view_new(void) -{ - return GTK_WIDGET(g_object_new(MU_TYPE_MSG_ATTACH_VIEW, NULL)); -} - -struct _CBData { - GtkListStore* store; - guint count; -}; -typedef struct _CBData CBData; - -static void -each_part(MuMsg* msg, MuMsgPart* part, CBData* cbdata) -{ - GtkTreeIter treeiter; - GdkPixbuf* pixbuf; - char ctype[128]; - - if (!mu_msg_part_maybe_attachment(part)) - return; - - if (!part->type || !part->subtype) - snprintf(ctype, sizeof(ctype), "%s", "application/octet-stream"); - else - snprintf(ctype, sizeof(ctype), "%s/%s", part->type, part->subtype); - - pixbuf = mu_widget_util_get_icon_pixbuf_for_content_type(ctype, 16); - if (!pixbuf) { - g_debug("%s: could not get icon pixbuf for '%s'", __func__, ctype); - pixbuf = - mu_widget_util_get_icon_pixbuf_for_content_type("application/octet-stream", 16); - } - - gtk_list_store_append(cbdata->store, &treeiter); - gtk_list_store_set(cbdata->store, - &treeiter, - NAME_COL, - mu_msg_part_get_filename(part, TRUE), - ICON_COL, - pixbuf, - PARTNUM_COL, - part->index, - -1); - if (pixbuf) - g_object_unref(pixbuf); - - ++cbdata->count; -} - -gint -mu_msg_attach_view_set_message(MuMsgAttachView* self, MuMsg* msg) -{ - GtkListStore* store; - CBData cbdata; - - g_return_val_if_fail(MU_IS_MSG_ATTACH_VIEW(self), -1); - - store = GTK_LIST_STORE(gtk_icon_view_get_model(GTK_ICON_VIEW(self))); - gtk_list_store_clear(store); - - set_message(self, msg); - - if (!msg) - return 0; - - cbdata.store = store; - cbdata.count = 0; - mu_msg_part_foreach(msg, MU_MSG_OPTION_NONE, (MuMsgPartForeachFunc)each_part, &cbdata); - - return cbdata.count; -} diff --git a/toys/mug/mu-msg-attach-view.hh b/toys/mug/mu-msg-attach-view.hh deleted file mode 100644 index 3a9360dc..00000000 --- a/toys/mug/mu-msg-attach-view.hh +++ /dev/null @@ -1,69 +0,0 @@ -/* -** Copyright (C) 2011-2021 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef MU_MSG_ATTACH_VIEW_HH__ -#define MU_MSG_ATTACH_VIEW_HH__ - -#include -#include - -G_BEGIN_DECLS - -/* convenience macros */ -#define MU_TYPE_MSG_ATTACH_VIEW (mu_msg_attach_view_get_type()) -#define MU_MSG_ATTACH_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), MU_TYPE_MSG_ATTACH_VIEW, MuMsgAttachView)) -#define MU_MSG_ATTACH_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), MU_TYPE_MSG_ATTACH_VIEW, MuMsgAttachViewClass)) -#define MU_IS_MSG_ATTACH_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MU_TYPE_MSG_ATTACH_VIEW)) -#define MU_IS_MSG_ATTACH_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), MU_TYPE_MSG_ATTACH_VIEW)) -#define MU_MSG_ATTACH_VIEW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), MU_TYPE_MSG_ATTACH_VIEW, MuMsgAttachViewClass)) - -typedef struct _MuMsgAttachView MuMsgAttachView; -typedef struct _MuMsgAttachViewClass MuMsgAttachViewClass; -typedef struct _MuMsgAttachViewPrivate MuMsgAttachViewPrivate; - -struct _MuMsgAttachView { - GtkIconView parent; - /* insert public members, if any */ - - /* private */ - MuMsgAttachViewPrivate* _priv; -}; - -struct _MuMsgAttachViewClass { - GtkIconViewClass parent_class; - void (*attach_activated)(MuMsgAttachView* obj, guint partnum, Mu::MuMsg* msg); -}; - -/* member functions */ -GType mu_msg_attach_view_get_type(void) G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget* mu_msg_attach_view_new(void); - -/* returns # of attachments */ -int mu_msg_attach_view_set_message(MuMsgAttachView* self, Mu::MuMsg* msg); - -G_END_DECLS - -#endif /*MU_MSG_ATTACH_VIEW_HH__*/ diff --git a/toys/mug/mu-msg-body-view.cc b/toys/mug/mu-msg-body-view.cc deleted file mode 100644 index 4bfed83d..00000000 --- a/toys/mug/mu-msg-body-view.cc +++ /dev/null @@ -1,334 +0,0 @@ -/* -** Copyright (C) 2011-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#include "mu-msg-body-view.hh" -#include - -using namespace Mu; - -enum _ViewMode { - VIEW_MODE_MSG, - VIEW_MODE_SOURCE, - VIEW_MODE_NOTE, - - VIEW_MODE_NONE -}; -typedef enum _ViewMode ViewMode; - -/* 'private'/'protected' functions */ -static void mu_msg_body_view_class_init(MuMsgBodyViewClass* klass); -static void mu_msg_body_view_init(MuMsgBodyView* obj); -static void mu_msg_body_view_finalize(GObject* obj); - -/* list my signals */ -enum { - ACTION_REQUESTED, - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - -struct _MuMsgBodyViewPrivate { - WebKitSettings* _settings; - MuMsg* _msg; - ViewMode _view_mode; -}; - -#define MU_MSG_BODY_VIEW_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MU_TYPE_MSG_BODY_VIEW, MuMsgBodyViewPrivate)) -/* globals */ -static WebKitWebViewClass* parent_class = NULL; - -static guint signals[LAST_SIGNAL] = {0}; - -G_DEFINE_TYPE(MuMsgBodyView, mu_msg_body_view, WEBKIT_TYPE_WEB_VIEW); - -static void -set_message(MuMsgBodyView* self, MuMsg* msg) -{ - if (self->_priv->_msg == msg) - return; /* nothing to todo */ - - if (self->_priv->_msg) { - mu_msg_unref(self->_priv->_msg); - self->_priv->_msg = NULL; - } - - if (msg) - self->_priv->_msg = mu_msg_ref(msg); -} - -static void -mu_msg_body_view_class_init(MuMsgBodyViewClass* klass) -{ - GObjectClass* gobject_class; - gobject_class = (GObjectClass*)klass; - - parent_class = (WebKitWebViewClass*)g_type_class_peek_parent(klass); - gobject_class->finalize = mu_msg_body_view_finalize; - - g_type_class_add_private(gobject_class, sizeof(MuMsgBodyViewPrivate)); - - signals[ACTION_REQUESTED] = - g_signal_new("action-requested", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(MuMsgBodyViewClass, action_requested), - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); -} - -static char* -save_file_for_cid(MuMsg* msg, const char* cid) -{ - gint idx; - gchar* filepath; - gboolean rv; - GError* err; - - g_return_val_if_fail(msg, NULL); - g_return_val_if_fail(cid, NULL); - - idx = mu_msg_find_index_for_cid(msg, MU_MSG_OPTION_NONE, cid); - if (idx < 0) { - g_warning("%s: cannot find %s", __func__, cid); - return NULL; - } - - filepath = mu_msg_part_get_cache_path(msg, MU_MSG_OPTION_NONE, idx, NULL); - if (!filepath) { - g_warning("%s: cannot create filepath", filepath); - return NULL; - } - - err = NULL; - rv = mu_msg_part_save(msg, MU_MSG_OPTION_USE_EXISTING, filepath, idx, &err); - if (!rv) { - g_warning("%s: failed to save %s: %s", - __func__, - filepath, - err && err->message ? err->message : "error"); - g_clear_error(&err); - g_free(filepath); - filepath = NULL; - } - - return filepath; -} - -static void -on_resource_load_started(MuMsgBodyView* self, - WebKitWebResource* resource, - WebKitURIRequest* request, - gpointer data) -{ - const char* uri; - MuMsg* msg; - - msg = self->_priv->_msg; - uri = webkit_uri_request_get_uri(request); - - /* g_warning ("%s: %s", __func__, uri); */ - - if (g_ascii_strncasecmp(uri, "cid:", 4) == 0) { - gchar* filepath; - filepath = save_file_for_cid(msg, uri); - if (filepath) { - gchar* fileuri; - fileuri = g_strdup_printf("file://%s", filepath); - webkit_uri_request_set_uri(request, fileuri); - g_free(fileuri); - g_free(filepath); - } - } -} - -static void -on_menu_item_activate(GtkMenuItem* item, MuMsgBodyView* self) -{ - g_signal_emit(G_OBJECT(self), - signals[ACTION_REQUESTED], - 0, - g_object_get_data(G_OBJECT(item), "action")); -} - -static void -popup_menu(MuMsgBodyView* self, guint button, guint32 activate_time) -{ - GtkWidget* menu; - int i; - struct { - const char* title; - const char* action; - ViewMode mode; - } actions[] = { - {"View source...", "view-source", VIEW_MODE_MSG}, - {"View message...", "view-message", VIEW_MODE_SOURCE}, - }; - - menu = gtk_menu_new(); - - for (i = 0; i != G_N_ELEMENTS(actions); ++i) { - GtkWidget* item; - - if (self->_priv->_view_mode != actions[i].mode) - continue; - - item = gtk_menu_item_new_with_label(actions[i].title); - g_object_set_data(G_OBJECT(item), "action", (gpointer)actions[i].action); - g_signal_connect(item, "activate", G_CALLBACK(on_menu_item_activate), self); - gtk_menu_attach(GTK_MENU(menu), item, 0, 1, i, i + 1); - gtk_widget_show(item); - } - gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, 0); -} - -static gboolean -on_button_press_event(MuMsgBodyView* self, GdkEventButton* event, gpointer data) -{ - /* ignore all but the first (typically, left) mouse button */ - switch (event->button) { - case 1: return FALSE; /* propagate, let widget handle it */ - case 3: - /* no popup menus for notes */ - if (self->_priv->_view_mode != VIEW_MODE_NOTE) - popup_menu(self, event->button, event->time); - break; - default: return TRUE; /* ignore */ - } - - return (event->button > 1) ? TRUE : FALSE; -} - -static void -mu_msg_body_view_init(MuMsgBodyView* obj) -{ - obj->_priv = MU_MSG_BODY_VIEW_GET_PRIVATE(obj); - - obj->_priv->_msg = NULL; - obj->_priv->_view_mode = VIEW_MODE_NONE; - - obj->_priv->_settings = webkit_settings_new(); - g_object_set(G_OBJECT(obj->_priv->_settings), - "enable-javascript", - FALSE, - "auto-load-images", - TRUE, - "enable-plugins", - FALSE, - NULL); - - webkit_web_view_set_settings(WEBKIT_WEB_VIEW(obj), obj->_priv->_settings); - - /* to support cid: */ - g_signal_connect(obj, "resource-load-started", G_CALLBACK(on_resource_load_started), NULL); - g_signal_connect(obj, "button-press-event", G_CALLBACK(on_button_press_event), NULL); -} - -static void -mu_msg_body_view_finalize(GObject* obj) -{ - MuMsgBodyViewPrivate* priv; - - priv = MU_MSG_BODY_VIEW_GET_PRIVATE(obj); - if (priv && priv->_settings) - g_object_unref(priv->_settings); - - set_message(MU_MSG_BODY_VIEW(obj), NULL); - - G_OBJECT_CLASS(parent_class)->finalize(obj); -} - -GtkWidget* -mu_msg_body_view_new(void) -{ - return GTK_WIDGET(g_object_new(MU_TYPE_MSG_BODY_VIEW, NULL)); -} - -static void -set_html(MuMsgBodyView* self, const char* html) -{ - g_return_if_fail(MU_IS_MSG_BODY_VIEW(self)); - - webkit_web_view_load_html(WEBKIT_WEB_VIEW(self), html ? html : "", NULL); -} - -static void -set_text(MuMsgBodyView* self, const char* txt) -{ - g_return_if_fail(MU_IS_MSG_BODY_VIEW(self)); - - webkit_web_view_load_plain_text(WEBKIT_WEB_VIEW(self), txt ? txt : ""); -} - -void -mu_msg_body_view_set_message(MuMsgBodyView* self, MuMsg* msg) -{ - const char* data; - - g_return_if_fail(self); - - set_message(self, msg); - - data = msg ? mu_msg_get_body_html(msg, MU_MSG_OPTION_NONE) : ""; - if (data) - set_html(self, data); - else - set_text(self, mu_msg_get_body_text(msg, MU_MSG_OPTION_NONE)); - - self->_priv->_view_mode = VIEW_MODE_MSG; -} - -void -mu_msg_body_view_set_message_source(MuMsgBodyView* self, MuMsg* msg) -{ - const gchar* path; - gchar* data; - - g_return_if_fail(MU_IS_MSG_BODY_VIEW(self)); - g_return_if_fail(msg); - - set_message(self, NULL); - - path = msg ? mu_msg_get_path(msg) : NULL; - - if (path && g_file_get_contents(path, &data, NULL, NULL)) { - set_text(self, data); - g_free(data); - } else - set_text(self, ""); - - self->_priv->_view_mode = VIEW_MODE_SOURCE; -} - -void -mu_msg_body_view_set_note(MuMsgBodyView* self, const gchar* html) -{ - g_return_if_fail(self); - g_return_if_fail(html); - - set_message(self, NULL); - - set_html(self, html); - - self->_priv->_view_mode = VIEW_MODE_NOTE; -} diff --git a/toys/mug/mu-msg-body-view.hh b/toys/mug/mu-msg-body-view.hh deleted file mode 100644 index 1bb582e8..00000000 --- a/toys/mug/mu-msg-body-view.hh +++ /dev/null @@ -1,71 +0,0 @@ -/* -** Copyright (C) 2011-2021 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef MU_MSG_BODY_VIEW_HH__ -#define MU_MSG_BODY_VIEW_HH__ - -#include -#include - -G_BEGIN_DECLS - -/* convenience macros */ -#define MU_TYPE_MSG_BODY_VIEW (mu_msg_body_view_get_type()) -#define MU_MSG_BODY_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), MU_TYPE_MSG_BODY_VIEW, MuMsgBodyView)) -#define MU_MSG_BODY_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), MU_TYPE_MSG_BODY_VIEW, MuMsgBodyViewClass)) -#define MU_IS_MSG_BODY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MU_TYPE_MSG_BODY_VIEW)) -#define MU_IS_MSG_BODY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MU_TYPE_MSG_BODY_VIEW)) -#define MU_MSG_BODY_VIEW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), MU_TYPE_MSG_BODY_VIEW, MuMsgBodyViewClass)) - -typedef struct _MuMsgBodyView MuMsgBodyView; -typedef struct _MuMsgBodyViewClass MuMsgBodyViewClass; -typedef struct _MuMsgBodyViewPrivate MuMsgBodyViewPrivate; - -struct _MuMsgBodyView { - WebKitWebView parent; - /* insert public members, if any */ - - /* private */ - MuMsgBodyViewPrivate* _priv; -}; - -struct _MuMsgBodyViewClass { - WebKitWebViewClass parent_class; - - /* supported actions: "reindex", "view-source" */ - void (*action_requested)(MuMsgBodyView* self, const char* action); -}; - -/* member functions */ -GType mu_msg_body_view_get_type(void) G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget* mu_msg_body_view_new(void); - -void mu_msg_body_view_set_message(MuMsgBodyView* self, Mu::MuMsg* msg); -void mu_msg_body_view_set_note(MuMsgBodyView* self, const gchar* html); -void mu_msg_body_view_set_message_source(MuMsgBodyView* self, Mu::MuMsg* msg); - -G_END_DECLS - -#endif /* MU_MSG_BODY_VIEW_HH__ */ diff --git a/toys/mug/mu-msg-header-view.cc b/toys/mug/mu-msg-header-view.cc deleted file mode 100644 index 8fa12515..00000000 --- a/toys/mug/mu-msg-header-view.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* -** Copyright (C) 2011-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ -#include -#include "mu-msg-header-view.hh" -#include "mu-msg.hh" - -#include -#include - -using namespace Mu; - -/* 'private'/'protected' functions */ -static void mu_msg_header_view_class_init(MuMsgHeaderViewClass* klass); -static void mu_msg_header_view_init(MuMsgHeaderView* obj); -static void mu_msg_header_view_finalize(GObject* obj); - -/* list my signals */ -enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - -struct _MuMsgHeaderViewPrivate { - GtkWidget* _grid; -}; -#define MU_MSG_HEADER_VIEW_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MU_TYPE_MSG_HEADER_VIEW, MuMsgHeaderViewPrivate)) -/* globals */ -static GtkBoxClass* parent_class = NULL; - -/* uncomment the following if you have defined any signals */ -/* static guint signals[LAST_SIGNAL] = {0}; */ - -G_DEFINE_TYPE(MuMsgHeaderView, mu_msg_header_view, GTK_TYPE_BOX); - -static void -mu_msg_header_view_class_init(MuMsgHeaderViewClass* klass) -{ - GObjectClass* gobject_class; - gobject_class = (GObjectClass*)klass; - - parent_class = (GtkBoxClass*)g_type_class_peek_parent(klass); - gobject_class->finalize = mu_msg_header_view_finalize; - - g_type_class_add_private(gobject_class, sizeof(MuMsgHeaderViewPrivate)); - - /* signal definitions go here, e.g.: */ - /* signals[MY_SIGNAL_1] = */ - /* g_signal_new ("my_signal_1",....); */ - /* signals[MY_SIGNAL_2] = */ - /* g_signal_new ("my_signal_2",....); */ - /* etc. */ -} - -static void -mu_msg_header_view_init(MuMsgHeaderView* obj) -{ - /* static GtkBoxClass *parent_class = NULL; */ - obj->_priv = MU_MSG_HEADER_VIEW_GET_PRIVATE(obj); - obj->_priv->_grid = NULL; -} - -static void -mu_msg_header_view_finalize(GObject* obj) -{ - G_OBJECT_CLASS(parent_class)->finalize(obj); -} - -GtkWidget* -mu_msg_header_view_new(void) -{ - return GTK_WIDGET(g_object_new(MU_TYPE_MSG_HEADER_VIEW, NULL)); -} - -static GtkWidget* -get_label(const gchar* txt, gboolean istitle) -{ - GtkWidget* label; - - label = gtk_label_new(NULL); - if (istitle) { - char* markup; - markup = g_strdup_printf("%s: ", txt); - gtk_label_set_markup(GTK_LABEL(label), markup); - gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT); - g_free(markup); - } else { - gtk_label_set_selectable(GTK_LABEL(label), TRUE); - gtk_label_set_text(GTK_LABEL(label), txt ? txt : ""); - gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); - } - - return label; -} - -G_GNUC_UNUSED static gboolean -add_row(GtkWidget* grid, guint row, const char* fieldname, const char* value, gboolean showempty) -{ - GtkWidget *label, *al; - - if (!value && !showempty) - return FALSE; - - gtk_grid_insert_row(GTK_GRID(grid), row); - - label = get_label(fieldname, TRUE); - al = gtk_alignment_new(0.0, 0.0, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(al), label); - - gtk_grid_attach(GTK_GRID(grid), al, 0, row, 1, 1); - - al = gtk_alignment_new(0.0, 1.0, 0.0, 0.0); - - label = get_label(value, FALSE); - gtk_container_add(GTK_CONTAINER(al), label); - gtk_grid_attach(GTK_GRID(grid), al, 1, row, 1, 1); - - return TRUE; -} - -static GtkWidget* -get_grid(Mu::MuMsg* msg) -{ - GtkWidget* grid; - int row; - - row = 0; - grid = gtk_grid_new(); /* 5 2 */ - - gtk_grid_insert_column(GTK_GRID(grid), 0); - gtk_grid_insert_column(GTK_GRID(grid), 1); - - if (add_row(grid, row, "From", mu_msg_get_from(msg), TRUE)) - ++row; - if (add_row(grid, row, "To", mu_msg_get_to(msg), FALSE)) - ++row; - if (add_row(grid, row, "Cc", mu_msg_get_cc(msg), FALSE)) - ++row; - if (add_row(grid, row, "Subject", mu_msg_get_subject(msg), TRUE)) - ++row; - if (add_row(grid, row, "Date", - time_to_string("%c", mu_msg_get_date(msg)).c_str(), TRUE)) - ++row; - - return grid; -} - -void -mu_msg_header_view_set_message(MuMsgHeaderView* self, Mu::MuMsg* msg) -{ - g_return_if_fail(MU_IS_MSG_HEADER_VIEW(self)); - - if (self->_priv->_grid) { - gtk_container_remove(GTK_CONTAINER(self), self->_priv->_grid); - self->_priv->_grid = NULL; - } - - if (msg) { - self->_priv->_grid = get_grid(msg); - gtk_box_pack_start(GTK_BOX(self), self->_priv->_grid, TRUE, TRUE, 0); - gtk_widget_show_all(self->_priv->_grid); - } -} diff --git a/toys/mug/mu-msg-header-view.hh b/toys/mug/mu-msg-header-view.hh deleted file mode 100644 index 7a51849c..00000000 --- a/toys/mug/mu-msg-header-view.hh +++ /dev/null @@ -1,69 +0,0 @@ -/* -** Copyright (C) 2011-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef __MU_MSG_HEADER_VIEW_H__ -#define __MU_MSG_HEADER_VIEW_H__ - -#include -#include - -G_BEGIN_DECLS - -/* convenience macros */ -#define MU_TYPE_MSG_HEADER_VIEW (mu_msg_header_view_get_type()) -#define MU_MSG_HEADER_VIEW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), MU_TYPE_MSG_HEADER_VIEW, MuMsgHeaderView)) -#define MU_MSG_HEADER_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), MU_TYPE_MSG_HEADER_VIEW, MuMsgHeaderViewClass)) -#define MU_IS_MSG_HEADER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MU_TYPE_MSG_HEADER_VIEW)) -#define MU_IS_MSG_HEADER_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), MU_TYPE_MSG_HEADER_VIEW)) -#define MU_MSG_HEADER_VIEW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), MU_TYPE_MSG_HEADER_VIEW, MuMsgHeaderViewClass)) - -typedef struct _MuMsgHeaderView MuMsgHeaderView; -typedef struct _MuMsgHeaderViewClass MuMsgHeaderViewClass; -typedef struct _MuMsgHeaderViewPrivate MuMsgHeaderViewPrivate; - -struct _MuMsgHeaderView { - GtkBox parent; - /* insert public members, if any */ - /* private */ - MuMsgHeaderViewPrivate* _priv; -}; - -struct _MuMsgHeaderViewClass { - GtkBoxClass parent_class; - /* insert signal callback declarations, e.g. */ - /* void (* my_event) (MuMsgHeaderView* obj); */ -}; - -/* member functions */ -GType mu_msg_header_view_get_type(void) G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget* mu_msg_header_view_new(void); - -struct MuMsg; -void mu_msg_header_view_set_message(MuMsgHeaderView* self, Mu::MuMsg* msg); - -G_END_DECLS - -#endif /* __MU_MSG_HEADER_VIEW_H__ */ diff --git a/toys/mug/mu-msg-view.cc b/toys/mug/mu-msg-view.cc deleted file mode 100644 index fba6b3f8..00000000 --- a/toys/mug/mu-msg-view.cc +++ /dev/null @@ -1,224 +0,0 @@ -/* -** Copyright (C) 2011-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#include - -#include "mu-msg-view.hh" -#include "mu-msg-body-view.hh" -#include "mu-msg-header-view.hh" -#include "mu-msg-attach-view.hh" -#include - -#include -#include - -using namespace Mu; - -/* 'private'/'protected' functions */ -static void mu_msg_view_class_init(MuMsgViewClass* klass); -static void mu_msg_view_init(MuMsgView* obj); -static void mu_msg_view_finalize(GObject* obj); - -/* list my signals */ -enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - -struct _MuMsgViewPrivate { - GtkWidget *_headers, *_attach, *_attachexpander, *_body; - Mu::MuMsg* _msg; -}; -#define MU_MSG_VIEW_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MU_TYPE_MSG_VIEW, MuMsgViewPrivate)) -/* globals */ -static GtkBoxClass* parent_class = NULL; - -/* uncomment the following if you have defined any signals */ -/* static guint signals[LAST_SIGNAL] = {0}; */ - -G_DEFINE_TYPE(MuMsgView, mu_msg_view, GTK_TYPE_BOX); - -static void -set_message(MuMsgView* self, Mu::MuMsg* msg) -{ - if (self->_priv->_msg == msg) - return; /* nothing to todo */ - - if (self->_priv->_msg) { - mu_msg_unref(self->_priv->_msg); - self->_priv->_msg = NULL; - } - - if (msg) - self->_priv->_msg = mu_msg_ref(msg); -} - -static void -mu_msg_view_class_init(MuMsgViewClass* klass) -{ - GObjectClass* gobject_class; - gobject_class = (GObjectClass*)klass; - - parent_class = (GtkBoxClass*)g_type_class_peek_parent(klass); - gobject_class->finalize = mu_msg_view_finalize; - - g_type_class_add_private(gobject_class, sizeof(MuMsgViewPrivate)); - - /* signal definitions go here, e.g.: */ - /* signals[MY_SIGNAL_1] = */ - /* g_signal_new ("my_signal_1",....); */ - /* signals[MY_SIGNAL_2] = */ - /* g_signal_new ("my_signal_2",....); */ - /* etc. */ -} - -static void -on_body_action_requested(GtkWidget* w, const char* action, MuMsgView* self) -{ - if (g_strcmp0(action, "view-source") == 0) { - if (self->_priv->_msg) - mu_msg_view_set_message_source(self, self->_priv->_msg); - - } else if (g_strcmp0(action, "view-message") == 0) { - if (self->_priv->_msg) - mu_msg_view_set_message(self, self->_priv->_msg); - - } else if (g_strcmp0(action, "reindex") == 0) - g_warning("reindex"); - else - g_warning("unknown action '%s'", action); -} - -static void -on_attach_activated(GtkWidget* w, guint partnum, Mu::MuMsg* msg) -{ - gchar* filepath; - GError* err; - - err = NULL; - filepath = mu_msg_part_get_cache_path(msg, MU_MSG_OPTION_NONE, partnum, &err); - if (!filepath) { - g_warning("failed to get cache path: %s", - err && err->message ? err->message : "error"); - g_clear_error(&err); - return; - } - - if (!mu_msg_part_save(msg, MU_MSG_OPTION_USE_EXISTING, filepath, partnum, &err)) { - g_warning("failed to save %s: %s", - filepath, - err && err->message ? err->message : "error"); - g_clear_error(&err); - return; - - } else - mu_util_play(filepath, TRUE, FALSE, NULL); - - g_free(filepath); -} - -static void -mu_msg_view_init(MuMsgView* self) -{ - gtk_orientable_set_orientation(GTK_ORIENTABLE(self), GTK_ORIENTATION_VERTICAL); - - self->_priv = MU_MSG_VIEW_GET_PRIVATE(self); - - self->_priv->_msg = NULL; - self->_priv->_headers = mu_msg_header_view_new(); - self->_priv->_attach = mu_msg_attach_view_new(); - self->_priv->_attachexpander = gtk_expander_new_with_mnemonic("_Attachments"); - - gtk_container_add(GTK_CONTAINER(self->_priv->_attachexpander), self->_priv->_attach); - g_signal_connect(self->_priv->_attach, - "attach-activated", - G_CALLBACK(on_attach_activated), - self); - - self->_priv->_body = mu_msg_body_view_new(); - g_signal_connect(self->_priv->_body, - "action-requested", - G_CALLBACK(on_body_action_requested), - self); - - gtk_box_pack_start(GTK_BOX(self), self->_priv->_headers, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(self), self->_priv->_attachexpander, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(self), self->_priv->_body, TRUE, TRUE, 2); -} - -static void -mu_msg_view_finalize(GObject* obj) -{ - set_message(MU_MSG_VIEW(obj), NULL); - - G_OBJECT_CLASS(parent_class)->finalize(obj); -} - -GtkWidget* -mu_msg_view_new(void) -{ - return GTK_WIDGET(g_object_new(MU_TYPE_MSG_VIEW, NULL)); -} - -void -mu_msg_view_set_message(MuMsgView* self, Mu::MuMsg* msg) -{ - gint attachnum; - - g_return_if_fail(MU_IS_MSG_VIEW(self)); - - set_message(self, msg); - - mu_msg_header_view_set_message(MU_MSG_HEADER_VIEW(self->_priv->_headers), msg); - attachnum = mu_msg_attach_view_set_message(MU_MSG_ATTACH_VIEW(self->_priv->_attach), msg); - - mu_msg_body_view_set_message(MU_MSG_BODY_VIEW(self->_priv->_body), msg); - - gtk_widget_set_visible(self->_priv->_headers, TRUE); - gtk_widget_set_visible(self->_priv->_attachexpander, attachnum > 0); - gtk_widget_set_visible(self->_priv->_body, TRUE); -} - -void -mu_msg_view_set_message_source(MuMsgView* self, Mu::MuMsg* msg) -{ - g_return_if_fail(MU_IS_MSG_VIEW(self)); - - set_message(self, msg); - - mu_msg_body_view_set_message_source(MU_MSG_BODY_VIEW(self->_priv->_body), msg); - - gtk_widget_set_visible(self->_priv->_headers, FALSE); - gtk_widget_set_visible(self->_priv->_attachexpander, FALSE); - gtk_widget_set_visible(self->_priv->_body, TRUE); -} - -void -mu_msg_view_set_note(MuMsgView* self, const gchar* html) -{ - g_return_if_fail(MU_IS_MSG_VIEW(self)); - - gtk_widget_set_visible(self->_priv->_headers, FALSE); - gtk_widget_set_visible(self->_priv->_attachexpander, FALSE); - gtk_widget_set_visible(self->_priv->_body, TRUE); - - mu_msg_body_view_set_note(MU_MSG_BODY_VIEW(self->_priv->_body), html); -} diff --git a/toys/mug/mu-msg-view.hh b/toys/mug/mu-msg-view.hh deleted file mode 100644 index 7a6dbfa0..00000000 --- a/toys/mug/mu-msg-view.hh +++ /dev/null @@ -1,68 +0,0 @@ -/* -** Copyright (C) 2011-2020Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef __MU_MSG_VIEW_H__ -#define __MU_MSG_VIEW_H__ - -#include -#include "mu-msg.hh" - -G_BEGIN_DECLS - -/* convenience macros */ -#define MU_TYPE_MSG_VIEW (mu_msg_view_get_type()) -#define MU_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), MU_TYPE_MSG_VIEW, MuMsgView)) -#define MU_MSG_VIEW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), MU_TYPE_MSG_VIEW, MuMsgViewClass)) -#define MU_IS_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), MU_TYPE_MSG_VIEW)) -#define MU_IS_MSG_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MU_TYPE_MSG_VIEW)) -#define MU_MSG_VIEW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), MU_TYPE_MSG_VIEW, MuMsgViewClass)) - -typedef struct _MuMsgView MuMsgView; -typedef struct _MuMsgViewClass MuMsgViewClass; -typedef struct _MuMsgViewPrivate MuMsgViewPrivate; - -struct _MuMsgView { - GtkBox parent; - /* private */ - MuMsgViewPrivate* _priv; -}; - -struct _MuMsgViewClass { - GtkBoxClass parent_class; - /* void (* my_event) (MuMsgView* obj); */ -}; - -/* member functions */ -GType mu_msg_view_get_type(void) G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget* mu_msg_view_new(void); - -struct MuMsg; - -void mu_msg_view_set_message(MuMsgView* self, Mu::MuMsg* msg); -void mu_msg_view_set_note(MuMsgView* self, const gchar* html); -void mu_msg_view_set_message_source(MuMsgView* self, Mu::MuMsg* msg); - -G_END_DECLS - -#endif /* __MU_MSG_VIEW_H__ */ diff --git a/toys/mug/mu-widget-util.c b/toys/mug/mu-widget-util.c deleted file mode 100644 index 777a728d..00000000 --- a/toys/mug/mu-widget-util.c +++ /dev/null @@ -1,94 +0,0 @@ -/* -** Copyright (C) 2011-2013 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - - -#include -#include -#include "mu-widget-util.h" - -static const char* -second_guess_content_type (const char *ctype) -{ - int i; - struct { - const char *orig, *subst; - } substtable [] = { - {"text", "text/plain"}, - {"image/pjpeg", "image/jpeg" } - }; - - for (i = 0; i != G_N_ELEMENTS(substtable); ++i) - if (g_str_has_prefix (ctype, substtable[i].orig)) - return substtable[i].subst; - - return "application/octet-stream"; -} - -static GdkPixbuf* -get_icon_pixbuf_for_content_type (const char *ctype, size_t size) -{ - GIcon *icon; - GdkPixbuf *pixbuf; - GError *err; - - icon = g_content_type_get_icon (ctype); - pixbuf = NULL; - err = NULL; - - /* based on a snippet from http://www.gtkforums.com/about4721.html */ - if (G_IS_THEMED_ICON(icon)) { - gchar const * const *names; - names = g_themed_icon_get_names (G_THEMED_ICON(icon)); - pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(), - *names, size, 0, &err); - } else if (G_IS_FILE_ICON(icon)) { - GFile *icon_file; - gchar *path; - icon_file = g_file_icon_get_file (G_FILE_ICON(icon)); - path = g_file_get_path (icon_file); - pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, &err); - g_free (path); - g_object_unref(icon_file); - } - g_object_unref(icon); - - if (err) { - g_warning ("error: %s\n", err->message); - g_clear_error (&err); - } - - return pixbuf; -} - - -GdkPixbuf* -mu_widget_util_get_icon_pixbuf_for_content_type (const char *ctype, size_t size) -{ - GdkPixbuf *pixbuf; - - g_return_val_if_fail (ctype, NULL); - g_return_val_if_fail (size > 0, NULL); - - pixbuf = get_icon_pixbuf_for_content_type (ctype, size); - if (!pixbuf) - pixbuf = get_icon_pixbuf_for_content_type - (second_guess_content_type (ctype), size); - - return pixbuf; -} diff --git a/toys/mug/mu-widget-util.h b/toys/mug/mu-widget-util.h deleted file mode 100644 index 99613287..00000000 --- a/toys/mug/mu-widget-util.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -** Copyright (C) 2011-2013 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef __MU_WIDGET_UTIL_H__ -#define __MU_WIDGET_UTIL_H__ - -#include - -G_BEGIN_DECLS -/** - * get a pixbuf (icon) for a certain content-type (ie., 'image/jpeg') - * - * @param ctype the content-type (MIME-type) - * @param size the size of the icon - * - * @return a new GdkPixbuf, or NULL in case of error. Use - * g_object_unref when the pixbuf is no longer needed. - */ -GdkPixbuf* mu_widget_util_get_icon_pixbuf_for_content_type (const char *ctype, - size_t size) - G_GNUC_WARN_UNUSED_RESULT; - - -G_END_DECLS - -#endif /*__MU_WIDGET_UTIL_H__*/ diff --git a/toys/mug/mug-msg-list-view.cc b/toys/mug/mug-msg-list-view.cc deleted file mode 100644 index aa5dcc30..00000000 --- a/toys/mug/mug-msg-list-view.cc +++ /dev/null @@ -1,430 +0,0 @@ -/* -** Copyright (C) 2008-2022 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#include "mug-msg-list-view.h" -#include "message/mu-message.hh" -#include "mu-query.hh" -#include "utils/mu-str.h" - -using namespace Mu; - -/* 'private'/'protected' functions */ -static void mug_msg_list_view_finalize(GObject* obj); - -/* list my signals */ -enum { MUG_MSG_SELECTED, MUG_ERROR_OCCURED, LAST_SIGNAL }; - -enum { - MUG_COL_DATESTR, - MUG_COL_MAILDIR, - MUG_COL_FLAGSSTR, - MUG_COL_FROM, - MUG_COL_TO, - MUG_COL_SUBJECT, - MUG_COL_PATH, - MUG_COL_PRIO, - MUG_COL_FLAGS, - MUG_COL_TIME, - MUG_N_COLS -}; - -typedef struct _MugMsgListViewPrivate MugMsgListViewPrivate; -struct _MugMsgListViewPrivate { - GtkTreeStore* _store; - char* _xpath; - char* _query; -}; -#define MUG_MSG_LIST_VIEW_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MUG_TYPE_MSG_LIST_VIEW, MugMsgListViewPrivate)) -/* globals */ -static GtkTreeViewClass* parent_class = NULL; - -/* uncomment the following if you have defined any signals */ -static guint signals[LAST_SIGNAL] = {0}; - -G_DEFINE_TYPE(MugMsgListView, mug_msg_list_view, GTK_TYPE_TREE_VIEW); - -static void -mug_msg_list_view_class_init(MugMsgListViewClass* klass) -{ - GObjectClass* gobject_class; - gobject_class = (GObjectClass*)klass; - - parent_class = (GtkTreeViewClass*)g_type_class_peek_parent(klass); - gobject_class->finalize = mug_msg_list_view_finalize; - - g_type_class_add_private(gobject_class, sizeof(MugMsgListViewPrivate)); - - signals[MUG_MSG_SELECTED] = g_signal_new("msg-selected", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(MugMsgListViewClass, msg_selected), - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - signals[MUG_ERROR_OCCURED] = - g_signal_new("error-occured", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(MugMsgListViewClass, error_occured), - NULL, - NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, - 1, - G_TYPE_UINT); -} - -static void -on_cursor_changed(GtkTreeView* tview, MugMsgListView* lst) -{ - GtkTreeSelection* sel; - GtkTreeIter iter; - MugMsgListViewPrivate* priv; - - priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(tview); - - sel = gtk_tree_view_get_selection(tview); - if (!sel) - return; /* hmmm */ - if (gtk_tree_selection_get_selected(sel, NULL, &iter)) { - char* path; - gtk_tree_model_get(GTK_TREE_MODEL(priv->_store), &iter, MUG_COL_PATH, &path, -1); - g_signal_emit(G_OBJECT(lst), signals[MUG_MSG_SELECTED], 0, path); - g_free(path); - } -} - -static void -treecell_func(GtkTreeViewColumn* tree_column, - GtkCellRenderer* renderer, - GtkTreeModel* tree_model, - GtkTreeIter* iter, - gpointer data) -{ - - Flags flags; - Priority prio; - - gtk_tree_model_get(tree_model, iter, MUG_COL_FLAGS, &flags, MUG_COL_PRIO, &prio, -1); - - g_object_set(G_OBJECT(renderer), - "weight", - any_of(flags & Flags::New) ? 800 : 400, - "weight", - any_of(flags & Flags::Seen) ? 400 : 800, - "foreground", - prio == Priority::High ? "red" : NULL, - NULL); -} - -/* sortcolidx == -1 means 'sortcolidx = colidx' */ -static void -append_col(GtkTreeView* treeview, const char* label, int colidx, int sortcolidx, gint maxwidth) -{ - GtkTreeViewColumn* col; - GtkCellRenderer* renderer; - - renderer = gtk_cell_renderer_text_new(); - g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); - - col = gtk_tree_view_column_new_with_attributes(label, renderer, "text", colidx, NULL); - g_object_set(G_OBJECT(col), "resizable", TRUE, NULL); - - gtk_tree_view_column_set_sort_indicator(col, TRUE); - - if (sortcolidx == -1) - sortcolidx = colidx; - gtk_tree_view_column_set_sort_column_id(col, sortcolidx); - gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); - - if (maxwidth) { - gtk_tree_view_column_set_fixed_width(col, maxwidth); - gtk_tree_view_column_set_expand(col, FALSE); - } else - gtk_tree_view_column_set_expand(col, TRUE); - - gtk_tree_view_column_set_cell_data_func(col, - renderer, - (GtkTreeCellDataFunc)treecell_func, - NULL, - NULL); - - gtk_tree_view_append_column(treeview, col); - - gtk_tree_view_columns_autosize(treeview); - gtk_tree_view_set_fixed_height_mode(treeview, TRUE); -} - -static void -mug_msg_list_view_init(MugMsgListView* obj) -{ - MugMsgListViewPrivate* priv; - GtkTreeView* tview; - - priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(obj); - - priv->_xpath = priv->_query = NULL; - priv->_store = gtk_tree_store_new(MUG_N_COLS, - G_TYPE_STRING, /* date */ - G_TYPE_STRING, /* folder */ - G_TYPE_STRING, /* flagstr */ - G_TYPE_STRING, /* from */ - G_TYPE_STRING, /* to */ - G_TYPE_STRING, /* subject */ - G_TYPE_STRING, /* path */ - G_TYPE_UINT, /* prio */ - G_TYPE_UINT, /* flags */ - G_TYPE_INT); /* timeval */ - - tview = GTK_TREE_VIEW(obj); - gtk_tree_view_set_model(tview, GTK_TREE_MODEL(priv->_store)); - gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(obj), TRUE); - gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(obj), GTK_TREE_VIEW_GRID_LINES_VERTICAL); - gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(obj), TRUE); - - append_col(tview, "Date", MUG_COL_DATESTR, MUG_COL_TIME, 80); - append_col(tview, "Folder", MUG_COL_MAILDIR, -1, 60); - append_col(tview, "F", MUG_COL_FLAGSSTR, -1, 25); - append_col(tview, "From", MUG_COL_FROM, -1, 0); - append_col(tview, "To", MUG_COL_TO, -1, 0); - append_col(tview, "Subject", MUG_COL_SUBJECT, -1, 0); - - g_signal_connect(G_OBJECT(obj), "cursor-changed", G_CALLBACK(on_cursor_changed), obj); -} - -static void -mug_msg_list_view_finalize(GObject* obj) -{ - MugMsgListViewPrivate* priv; - priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(obj); - - if (priv->_store) - g_object_unref(priv->_store); - - g_free(priv->_xpath); - g_free(priv->_query); - - G_OBJECT_CLASS(parent_class)->finalize(obj); -} - -void -mug_msg_list_view_move_first(MugMsgListView* self) -{ - GtkTreePath* path; - - g_return_if_fail(MUG_IS_MSG_LIST_VIEW(self)); - - path = gtk_tree_path_new_first(); - gtk_tree_view_set_cursor(GTK_TREE_VIEW(self), path, NULL, FALSE); - - gtk_tree_path_free(path); -} - -static gboolean -msg_list_view_move(MugMsgListView* self, gboolean next) -{ - GtkTreePath* path; - - gtk_tree_view_get_cursor(GTK_TREE_VIEW(self), &path, NULL); - if (!path) - return FALSE; - - if (next) - gtk_tree_path_next(path); - else - gtk_tree_path_prev(path); - - gtk_tree_view_set_cursor(GTK_TREE_VIEW(self), path, NULL, FALSE); - gtk_tree_path_free(path); - - return TRUE; -} - -gboolean -mug_msg_list_view_move_next(MugMsgListView* self) -{ - g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), FALSE); - - return msg_list_view_move(self, TRUE); -} - -gboolean -mug_msg_list_view_move_prev(MugMsgListView* self) -{ - g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), FALSE); - - return msg_list_view_move(self, FALSE); -} - -GtkWidget* -mug_msg_list_view_new(const char* xpath) -{ - GtkWidget* w; - MugMsgListViewPrivate* priv; - - g_return_val_if_fail(xpath, NULL); - - w = GTK_WIDGET(g_object_new(MUG_TYPE_MSG_LIST_VIEW, NULL)); - - priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(w); - priv->_xpath = g_strdup(xpath); - - return w; -} - -static gchar* -empty_or_display_contact(const gchar* str) -{ - if (!str || *str == '\0') - return g_strdup("-"); - else - return mu_str_display_contact(str); -} - -static Mu::Option -run_query(const char* xpath, const char* expr, MugMsgListView* self) -{ - Mu::Store store{xpath}; - - return store.run_query(expr, - Field::Id::Date, - Mu::QueryFlags::Descending | Mu::QueryFlags::SkipUnreadable | - Mu::QueryFlags::SkipDuplicates | Mu::QueryFlags::IncludeRelated | - Mu::QueryFlags::Threading); -} - -static void -add_row(GtkTreeStore* store, MuMsg* msg, GtkTreeIter* treeiter) -{ - gchar * from, *to; - time_t timeval; - std::string flag_str; - - timeval = mu_msg_get_date(msg); - const auto datestr{timeval == 0 ? - std::string{"-"} : time_to_string("%c", timeval)}; - from = empty_or_display_contact(mu_msg_get_from(msg)); - to = empty_or_display_contact(mu_msg_get_to(msg)); - - flag_str = to_string(mu_msg_get_flags(msg)); - - /* if (0) { */ - /* GtkTreeIter myiter; */ - /* if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(store), */ - /* &myiter, path)) */ - /* g_warning ("%s: cannot get iter for %s", - * __func__, path); */ - /* } */ - - gtk_tree_store_set(store, - treeiter, - MUG_COL_DATESTR, - datestr, - MUG_COL_MAILDIR, - mu_msg_get_maildir(msg), - MUG_COL_FLAGSSTR, - flag_str.c_str(), - MUG_COL_FROM, - from, - MUG_COL_TO, - to, - MUG_COL_SUBJECT, - mu_msg_get_subject(msg), - MUG_COL_PATH, - mu_msg_get_path(msg), - MUG_COL_PRIO, - mu_msg_get_prio(msg), - MUG_COL_FLAGS, - mu_msg_get_flags(msg), - MUG_COL_TIME, - datestr.c_str(), - -1); - g_free(from); - g_free(to); -} - -static int -update_model(GtkTreeStore* store, const char* xpath, const char* query, MugMsgListView* self) -{ - const auto res{run_query(xpath, query, self)}; - if (!res) { - g_warning("error: running query failed"); - return -1; - } - - auto count{0}; - - std::string prev_thread_path; - for (auto&& it : *res) { - GtkTreeIter treeiter, prev_treeiter; - - const auto thread_path{it.query_match().thread_path}; - - if (prev_thread_path.find(thread_path) == 0) - gtk_tree_store_append(store, &treeiter, &prev_treeiter); - else - gtk_tree_store_append(store, &treeiter, NULL); - - /* don't unref msg */ - add_row(store, it.floating_msg(), &treeiter); - - // prev_ti = ti; - prev_treeiter = treeiter; - prev_thread_path = thread_path; - ++count; - } - - return count; -} - -int -mug_msg_list_view_query(MugMsgListView* self, const char* query) -{ - MugMsgListViewPrivate* priv; - gboolean rv; - - g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), FALSE); - - priv = MUG_MSG_LIST_VIEW_GET_PRIVATE(self); - gtk_tree_store_clear(priv->_store); - - g_free(priv->_query); - priv->_query = query ? g_strdup(query) : NULL; - - if (!query) - return TRUE; - - rv = update_model(priv->_store, priv->_xpath, query, self); - - gtk_tree_view_expand_all(GTK_TREE_VIEW(self)); - - return rv; -} - -const gchar* -mug_msg_list_view_get_query(MugMsgListView* self) -{ - g_return_val_if_fail(MUG_IS_MSG_LIST_VIEW(self), NULL); - - return MUG_MSG_LIST_VIEW_GET_PRIVATE(self)->_query; -} diff --git a/toys/mug/mug-msg-list-view.h b/toys/mug/mug-msg-list-view.h deleted file mode 100644 index 71b4260c..00000000 --- a/toys/mug/mug-msg-list-view.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -** Copyright (C) 2008-2013 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef __MUG_MSG_LIST_VIEW_H__ -#define __MUG_MSG_LIST_VIEW_H__ - -#include -#include - -G_BEGIN_DECLS -/* convenience macros */ -#define MUG_TYPE_MSG_LIST_VIEW (mug_msg_list_view_get_type()) -#define MUG_MSG_LIST_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_MSG_LIST_VIEW,MugMsgListView)) -#define MUG_MSG_LIST_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_MSG_LIST_VIEW,MugMsgListViewClass)) -#define MUG_IS_MSG_LIST_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_MSG_LIST_VIEW)) -#define MUG_IS_MSG_LIST_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_MSG_LIST_VIEW)) -#define MUG_MSG_LIST_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_MSG_LIST_VIEW,MugMsgListViewClass)) -typedef struct _MugMsgListView MugMsgListView; -typedef struct _MugMsgListViewClass MugMsgListViewClass; - -struct _MugMsgListView { - GtkTreeView parent; - /* insert public members, if any */ -}; - -enum _MugError { - MUG_ERROR_XAPIAN_NOT_UPTODATE, - MUG_ERROR_XAPIAN_DIR, - MUG_ERROR_QUERY, - MUG_ERROR_OTHER -}; -typedef enum _MugError MugError; - -struct _MugMsgListViewClass { - GtkTreeViewClass parent_class; - /* insert signal callback declarations, e.g. */ - void (*msg_selected) (MugMsgListView * obj, const char *msgpath); - void (*error_occured) (MugMsgListView * obj, MugError err); -}; - -/* member functions */ -GType -mug_msg_list_view_get_type (void) - G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget * -mug_msg_list_view_new (const char *xpath); - -int -mug_msg_list_view_query (MugMsgListView * self, const char *query); - -void -mug_msg_list_view_move_first (MugMsgListView * self); - -gboolean -mug_msg_list_view_move_prev (MugMsgListView * self); -gboolean -mug_msg_list_view_move_next (MugMsgListView * self); - -const gchar * -mug_msg_list_view_get_query (MugMsgListView * self); - -G_END_DECLS -#endif /* __MUG_MSG_LIST_VIEW_H__ */ diff --git a/toys/mug/mug-msg-view.cc b/toys/mug/mug-msg-view.cc deleted file mode 100644 index 1bb33796..00000000 --- a/toys/mug/mug-msg-view.cc +++ /dev/null @@ -1,148 +0,0 @@ -/* -** Copyright (C) 2008-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ -#include "config.h" - -#include -#include "mu-msg-view.hh" -#include "mug-msg-view.h" -#include "mu-msg.hh" -#include "utils/mu-str.h" - -using namespace Mu; - -/* 'private'/'protected' functions */ -static void mug_msg_view_class_init(MugMsgViewClass* klass); -static void mug_msg_view_init(MugMsgView* obj); -static void mug_msg_view_finalize(GObject* obj); - -/* list my signals */ -enum { - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - -typedef struct _MugMsgViewPrivate MugMsgViewPrivate; -struct _MugMsgViewPrivate { - GtkWidget* _view; -}; -#define MUG_MSG_VIEW_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MUG_TYPE_MSG_VIEW, MugMsgViewPrivate)) -/* globals */ - -static GtkBoxClass* parent_class = NULL; -G_DEFINE_TYPE(MugMsgView, mug_msg_view, GTK_TYPE_BOX); - -/* uncomment the following if you have defined any signals */ -/* static guint signals[LAST_SIGNAL] = {0}; */ - -static void -mug_msg_view_class_init(MugMsgViewClass* klass) -{ - GObjectClass* gobject_class; - gobject_class = (GObjectClass*)klass; - - parent_class = (GtkBoxClass*)g_type_class_peek_parent(klass); - gobject_class->finalize = mug_msg_view_finalize; - - g_type_class_add_private(gobject_class, sizeof(MugMsgViewPrivate)); - - /* signal definitions go here, e.g.: */ - /* signals[MY_SIGNAL_1] = */ - /* g_signal_new ("my_signal_1",....); */ - /* signals[MY_SIGNAL_2] = */ - /* g_signal_new ("my_signal_2",....); */ - /* etc. */ -} - -static void -mug_msg_view_init(MugMsgView* obj) -{ - MugMsgViewPrivate* priv; - GtkWidget* scrolled; - - priv = MUG_MSG_VIEW_GET_PRIVATE(obj); - - priv->_view = mu_msg_view_new(); - - scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(scrolled), priv->_view); - - gtk_box_pack_start(GTK_BOX(obj), scrolled, TRUE, TRUE, 0); -} - -static void -mug_msg_view_finalize(GObject* obj) -{ - /* free/unref instance resources here */ - G_OBJECT_CLASS(parent_class)->finalize(obj); -} - -GtkWidget* -mug_msg_view_new(void) -{ - return GTK_WIDGET(g_object_new(MUG_TYPE_MSG_VIEW, NULL)); -} - -gboolean -mug_msg_view_set_msg(MugMsgView* self, const char* msgpath) -{ - MugMsgViewPrivate* priv; - g_return_val_if_fail(MUG_IS_MSG_VIEW(self), FALSE); - - priv = MUG_MSG_VIEW_GET_PRIVATE(self); - - if (!msgpath) - mu_msg_view_set_message(MU_MSG_VIEW(priv->_view), NULL); - else { - Mu::MuMsg* msg; - - if (access(msgpath, R_OK) == 0) { - msg = mu_msg_new_from_file(msgpath, NULL, NULL); - mu_msg_view_set_message(MU_MSG_VIEW(priv->_view), msg); - if (msg) - mu_msg_unref(msg); - } else { - gchar* note; - note = g_strdup_printf("

Note


" - "

Message %s does not seem to be present " - "on the file system." - "

Maybe you need to run mu index?", - msgpath); - mu_msg_view_set_note(MU_MSG_VIEW(priv->_view), note); - g_free(note); - } - } - - return TRUE; -} - -void -mug_msg_view_set_note(MugMsgView* self, const char* html) -{ - MugMsgViewPrivate* priv; - g_return_if_fail(MUG_IS_MSG_VIEW(self)); - - priv = MUG_MSG_VIEW_GET_PRIVATE(self); - - mu_msg_view_set_note(MU_MSG_VIEW(priv->_view), html); -} diff --git a/toys/mug/mug-msg-view.h b/toys/mug/mug-msg-view.h deleted file mode 100644 index 96f9da79..00000000 --- a/toys/mug/mug-msg-view.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -** Copyright (C) 2010-2013 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef __MUG_MSG_VIEW_H__ -#define __MUG_MSG_VIEW_H__ - -#include -/* other include files */ - -G_BEGIN_DECLS -/* convenience macros */ -#define MUG_TYPE_MSG_VIEW (mug_msg_view_get_type()) -#define MUG_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_MSG_VIEW,MugMsgView)) -#define MUG_MSG_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_MSG_VIEW,MugMsgViewClass)) -#define MUG_IS_MSG_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_MSG_VIEW)) -#define MUG_IS_MSG_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_MSG_VIEW)) -#define MUG_MSG_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_MSG_VIEW,MugMsgViewClass)) -typedef struct _MugMsgView MugMsgView; -typedef struct _MugMsgViewClass MugMsgViewClass; - -struct _MugMsgView { - GtkBox parent; -}; - -struct _MugMsgViewClass { - GtkBoxClass parent_class; - /* insert signal callback declarations, e.g. */ - /* void (* my_event) (MugMsg* obj); */ -}; - -/* member functions */ -GType mug_msg_view_get_type (void) G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget* mug_msg_view_new (void); -gboolean mug_msg_view_set_msg (MugMsgView * self, const char *msgpath); -void mug_msg_view_set_note (MugMsgView * self, const char* html); - -G_END_DECLS - -#endif /* __MUG_MSG_VIEW_H__ */ diff --git a/toys/mug/mug-query-bar.c b/toys/mug/mug-query-bar.c deleted file mode 100644 index 6e488432..00000000 --- a/toys/mug/mug-query-bar.c +++ /dev/null @@ -1,112 +0,0 @@ -/* mug-query-bar.c */ - -/* insert (c)/licensing information) */ - -#include "mug-query-bar.h" -/* include other impl specific header files */ - -/* 'private'/'protected' functions */ -static void mug_query_bar_class_init (MugQueryBarClass * klass); -static void mug_query_bar_init (MugQueryBar * obj); -static void mug_query_bar_finalize (GObject * obj); - -/* list my signals */ -enum { - MUG_QUERY_CHANGED, - LAST_SIGNAL -}; - -typedef struct _MugQueryBarPrivate MugQueryBarPrivate; -struct _MugQueryBarPrivate { - GtkWidget *_entry; -}; -#define MUG_QUERY_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ - MUG_TYPE_QUERY_BAR, \ - MugQueryBarPrivate)) -/* globals */ -static GtkContainerClass *parent_class = NULL; - - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (MugQueryBar, mug_query_bar, GTK_TYPE_BOX); - -static void -mug_query_bar_class_init (MugQueryBarClass * klass) -{ - GObjectClass *gobject_class; - gobject_class = (GObjectClass *) klass; - - parent_class = g_type_class_peek_parent (klass); - gobject_class->finalize = mug_query_bar_finalize; - - g_type_class_add_private (gobject_class, sizeof (MugQueryBarPrivate)); - - /* signal definitions go here, e.g.: */ - signals[MUG_QUERY_CHANGED] = - g_signal_new ("query_changed", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (MugQueryBarClass, query_changed), - NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); -} - -static void -on_entry_activated (GtkWidget * w, MugQueryBar * bar) -{ - g_signal_emit (G_OBJECT (bar), signals[MUG_QUERY_CHANGED], 0, - gtk_entry_get_text (GTK_ENTRY (w))); -} - -static void -mug_query_bar_init (MugQueryBar * obj) -{ - MugQueryBarPrivate *priv; - - priv = MUG_QUERY_BAR_GET_PRIVATE (obj); - - priv->_entry = gtk_entry_new (); - - g_signal_connect (priv->_entry, "activate", - G_CALLBACK (on_entry_activated), obj); - - gtk_box_pack_start (GTK_BOX (obj), priv->_entry, TRUE, TRUE, 0); -} - -static void -mug_query_bar_finalize (GObject * obj) -{ -/* free/unref instance resources here */ - G_OBJECT_CLASS (parent_class)->finalize (obj); -} - -GtkWidget * -mug_query_bar_new (void) -{ - return GTK_WIDGET (g_object_new (MUG_TYPE_QUERY_BAR, NULL)); -} - -void -mug_query_bar_set_query (MugQueryBar * self, const char *query, gboolean run) -{ - MugQueryBarPrivate *priv; - - g_return_if_fail (MUG_IS_QUERY_BAR (self)); - priv = MUG_QUERY_BAR_GET_PRIVATE (self); - - gtk_entry_set_text (GTK_ENTRY (priv->_entry), query ? query : ""); - - if (run) - on_entry_activated (priv->_entry, self); -} - -void -mug_query_bar_grab_focus (MugQueryBar * self) -{ - g_return_if_fail (MUG_IS_QUERY_BAR (self)); - - gtk_widget_grab_focus - (GTK_WIDGET (MUG_QUERY_BAR_GET_PRIVATE (self)->_entry)); -} diff --git a/toys/mug/mug-query-bar.h b/toys/mug/mug-query-bar.h deleted file mode 100644 index bb011a92..00000000 --- a/toys/mug/mug-query-bar.h +++ /dev/null @@ -1,52 +0,0 @@ -/* mug-query-bar.h */ -/* insert (c)/licensing information) */ - -#ifndef __MUG_QUERY_BAR_H__ -#define __MUG_QUERY_BAR_H__ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /*HAVE_CONFIG*/ - -#include - -G_BEGIN_DECLS -/* convenience macros */ -#define MUG_TYPE_QUERY_BAR (mug_query_bar_get_type()) -#define MUG_QUERY_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_QUERY_BAR,MugQueryBar)) -#define MUG_QUERY_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_QUERY_BAR,MugQueryBarClass)) -#define MUG_IS_QUERY_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_QUERY_BAR)) -#define MUG_IS_QUERY_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_QUERY_BAR)) -#define MUG_QUERY_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_QUERY_BAR,MugQueryBarClass)) -typedef struct _MugQueryBar MugQueryBar; -typedef struct _MugQueryBarClass MugQueryBarClass; - -struct _MugQueryBar { - GtkBox parent; -}; - -struct _MugQueryBarClass { - GtkBox parent; - GtkBoxClass parent_class; - /* insert signal callback declarations, e.g. */ - void (*query_changed) (MugQueryBar * obj, const char *query); -}; - -/* member functions */ -GType -mug_query_bar_get_type (void) - G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget * -mug_query_bar_new (void); - -void -mug_query_bar_grab_focus (MugQueryBar * self); - -void -mug_query_bar_set_query (MugQueryBar * self, const char *query, gboolean run); - -G_END_DECLS -#endif /* __MUG_QUERY_BAR_H__ */ diff --git a/toys/mug/mug-shortcuts.cc b/toys/mug/mug-shortcuts.cc deleted file mode 100644 index ba494eec..00000000 --- a/toys/mug/mug-shortcuts.cc +++ /dev/null @@ -1,148 +0,0 @@ -/* -** Copyright (C) 2010-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#include "mug-shortcuts.h" -#include "mu-bookmarks.hh" - -/* include other impl specific header files */ - -/* 'private'/'protected' functions */ -static void mug_shortcuts_class_init(MugShortcutsClass* klass); -static void mug_shortcuts_init(MugShortcuts* obj); -static void mug_shortcuts_finalize(GObject* obj); - -#define MUG_SHORTCUT_BOOKMARK "bookmark" - -/* list my signals */ -enum { - SHORTCUT_CLICKED, - /* MY_SIGNAL_1, */ - /* MY_SIGNAL_2, */ - LAST_SIGNAL -}; - -struct _MugShortcutsPrivate { - GtkWidget* _bbox; -}; -#define MUG_SHORTCUTS_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE((o), MUG_TYPE_SHORTCUTS, MugShortcutsPrivate)) -/* globals */ - -static guint signals[LAST_SIGNAL] = {0}; - -static GtkBoxClass* parent_class = NULL; -G_DEFINE_TYPE(MugShortcuts, mug_shortcuts, GTK_TYPE_BOX); - -static void -mug_shortcuts_class_init(MugShortcutsClass* klass) -{ - GObjectClass* gobject_class; - gobject_class = (GObjectClass*)klass; - - parent_class = (GtkBoxClass*)g_type_class_peek_parent(klass); - gobject_class->finalize = mug_shortcuts_finalize; - - g_type_class_add_private(gobject_class, sizeof(MugShortcutsPrivate)); - - /* signal definitions go here, e.g.: */ - signals[SHORTCUT_CLICKED] = g_signal_new("clicked", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(MugShortcutsClass, clicked), - NULL, - NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - - /* signals[MY_SIGNAL_2] = */ - /* g_signal_new ("my_signal_2",....); */ - /* etc. */ -} - -static void -mug_shortcuts_init(MugShortcuts* obj) -{ - obj->_priv = MUG_SHORTCUTS_GET_PRIVATE(obj); - obj->_priv->_bbox = gtk_button_box_new(GTK_ORIENTATION_VERTICAL); - - gtk_button_box_set_layout(GTK_BUTTON_BOX(obj->_priv->_bbox), GTK_BUTTONBOX_START); - gtk_box_pack_start(GTK_BOX(obj), obj->_priv->_bbox, TRUE, TRUE, 0); -} - -static void -mug_shortcuts_finalize(GObject* obj) -{ - /* free/unref instance resources here */ - G_OBJECT_CLASS(parent_class)->finalize(obj); -} - -static void -on_button_clicked(GtkWidget* button, MugShortcuts* self) -{ - g_signal_emit(G_OBJECT(self), - signals[SHORTCUT_CLICKED], - 0, - (const gchar*)g_object_get_data(G_OBJECT(button), MUG_SHORTCUT_BOOKMARK)); -} - -static void -each_bookmark(const char* key, const char* val, MugShortcuts* self) -{ - GtkWidget* button; - - button = gtk_button_new_with_label(key); - g_object_set_data_full(G_OBJECT(button), MUG_SHORTCUT_BOOKMARK, g_strdup(val), g_free); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_button_clicked), self); - - gtk_container_add(GTK_CONTAINER(self->_priv->_bbox), button); -} - -static gboolean -init_shortcuts(MugShortcuts* self, const char* bmpath) -{ - MuBookmarks* bookmarks; - - bookmarks = mu_bookmarks_new(bmpath); - if (!bookmarks) - return TRUE; - - mu_bookmarks_foreach(bookmarks, (MuBookmarksForeachFunc)each_bookmark, self); - - mu_bookmarks_destroy(bookmarks); - return TRUE; -} - -GtkWidget* -mug_shortcuts_new(const char* bmpath) -{ - MugShortcuts* self; - - self = MUG_SHORTCUTS(g_object_new(MUG_TYPE_SHORTCUTS, NULL)); - if (!init_shortcuts(self, bmpath)) { - g_object_unref(self); - return NULL; - } - - return GTK_WIDGET(self); -} - -/* following: other function implementations */ -/* such as mug_shortcuts_do_something, or mug_shortcuts_has_foo */ diff --git a/toys/mug/mug-shortcuts.h b/toys/mug/mug-shortcuts.h deleted file mode 100644 index f8df47f4..00000000 --- a/toys/mug/mug-shortcuts.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -** Copyright (C) 2010 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#ifndef __MUG_SHORTCUTS_H__ -#define __MUG_SHORTCUTS_H__ - -#if HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ - - -#include -/* other include files */ - -G_BEGIN_DECLS -/* convenience macros */ -#define MUG_TYPE_SHORTCUTS (mug_shortcuts_get_type()) -#define MUG_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MUG_TYPE_SHORTCUTS,MugShortcuts)) -#define MUG_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MUG_TYPE_SHORTCUTS,MugShortcutsClass)) -#define MUG_IS_SHORTCUTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MUG_TYPE_SHORTCUTS)) -#define MUG_IS_SHORTCUTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MUG_TYPE_SHORTCUTS)) -#define MUG_SHORTCUTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MUG_TYPE_SHORTCUTS,MugShortcutsClass)) -typedef struct _MugShortcuts MugShortcuts; -typedef struct _MugShortcutsClass MugShortcutsClass; -typedef struct _MugShortcutsPrivate MugShortcutsPrivate; - -struct _MugShortcuts { - GtkBox parent; - /* private */ - MugShortcutsPrivate *_priv; -}; - -struct _MugShortcutsClass { - GtkBoxClass parent_class; - void (*clicked) (MugShortcuts * obj, const char *query); -}; - -/* member functions */ -GType mug_shortcuts_get_type (void) G_GNUC_CONST; - -/* parameter-less _new function (constructor) */ -/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */ -GtkWidget * -mug_shortcuts_new (const char *bmpath); - -/* fill in other public functions, e.g.: */ -/* void mug_shortcuts_do_something (MugShortcuts *self, const gchar* param); */ -/* gboolean mug_shortcuts_has_foo (MugShortcuts *self, gint value); */ - -G_END_DECLS - -#endif /* __MUG_SHORTCUTS_H__ */ diff --git a/toys/mug/mug.cc b/toys/mug/mug.cc deleted file mode 100644 index 0a17d0ad..00000000 --- a/toys/mug/mug.cc +++ /dev/null @@ -1,401 +0,0 @@ -/* -** Copyright (C) 2010-2020 Dirk-Jan C. Binnema -** -** This program is free software; you can redistribute it and/or modify it -** under the terms of the GNU General Public License as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -#include "config.h" - -#include -#include -#include /* for memset */ - -#include -#include -#include - -#include "mug-msg-list-view.h" -#include "mug-query-bar.h" -#include "mug-msg-view.h" -#include "mug-shortcuts.h" - -struct _MugData { - GtkWidget* win; - GtkWidget* statusbar; - GtkWidget* mlist; - GtkWidget* toolbar; - GtkWidget* msgview; - GtkWidget* querybar; - GtkWidget* shortcuts; - gchar* muhome; -}; -typedef struct _MugData MugData; - -static void -about_mug(MugData* mugdata) -{ - GtkWidget* about; - about = gtk_message_dialog_new(GTK_WINDOW(mugdata->win), - GTK_DIALOG_MODAL, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "Mug version %s\n" - "A graphical frontend to the 'mu' e-mail search engine\n\n" - "(c) 2010-2013 Dirk-Jan C. Binnema\n" - "Released under the terms of the GPLv3+", - VERSION); - - gtk_dialog_run(GTK_DIALOG(about)); - gtk_widget_destroy(about); -} - -enum _ToolAction { - ACTION_PREV_MSG = 1, - ACTION_NEXT_MSG, - ACTION_REINDEX, - ACTION_DO_QUIT, - ACTION_ABOUT, - ACTION_SEPARATOR /* pseudo action */ -}; -typedef enum _ToolAction ToolAction; - -static void -on_tool_button_clicked(GtkToolButton* btn, MugData* mugdata) -{ - ToolAction action; - action = (ToolAction)GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(btn), "action")); - switch (action) { - case ACTION_DO_QUIT: gtk_main_quit(); break; - case ACTION_NEXT_MSG: mug_msg_list_view_move_next(MUG_MSG_LIST_VIEW(mugdata->mlist)); break; - case ACTION_PREV_MSG: mug_msg_list_view_move_prev(MUG_MSG_LIST_VIEW(mugdata->mlist)); break; - case ACTION_ABOUT: about_mug(mugdata); break; - default: g_print("%u\n", action); - } -} - -static GtkToolItem* -tool_button(const char* name) -{ - GtkWidget* icon; - - icon = gtk_image_new_from_icon_name(name, GTK_ICON_SIZE_SMALL_TOOLBAR); - - return gtk_menu_tool_button_new(icon, NULL); -} - -static GtkToolItem* -get_connected_tool_button(const char* stock_id, ToolAction action, MugData* mugdata) -{ - GtkToolItem* btn; - - btn = tool_button(stock_id); - g_object_set_data(G_OBJECT(btn), "action", GUINT_TO_POINTER(action)); - g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(on_tool_button_clicked), mugdata); - return btn; -} - -static GtkWidget* -mug_toolbar(MugData* mugdata) -{ - GtkWidget* toolbar; - int i; - struct { - const char* stock_id; - ToolAction action; - } tools[] = {{"go-up", ACTION_PREV_MSG}, - {"go-down", ACTION_NEXT_MSG}, - {NULL, ACTION_SEPARATOR}, - {"view-refresh", ACTION_REINDEX}, - {NULL, ACTION_SEPARATOR}, - {"help-about", ACTION_ABOUT}, - {NULL, ACTION_SEPARATOR}, - {"application-exit", ACTION_DO_QUIT}}; - - toolbar = gtk_toolbar_new(); - for (i = 0; i != G_N_ELEMENTS(tools); ++i) { - if (tools[i].action == ACTION_SEPARATOR) { /* separator? */ - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), i); - continue; - } else /* nope: a real item */ - gtk_toolbar_insert( - GTK_TOOLBAR(toolbar), - get_connected_tool_button(tools[i].stock_id, tools[i].action, mugdata), - i); - } - - return toolbar; -} - -static void -on_shortcut_clicked(GtkWidget* w, const gchar* query, MugData* mdata) -{ - mug_query_bar_set_query(MUG_QUERY_BAR(mdata->querybar), query, TRUE); -} - -static GtkWidget* -mug_shortcuts_bar(MugData* data) -{ - data->shortcuts = mug_shortcuts_new(mu_runtime_path(MU_RUNTIME_PATH_BOOKMARKS)); - - g_signal_connect(G_OBJECT(data->shortcuts), - "clicked", - G_CALLBACK(on_shortcut_clicked), - data); - - return data->shortcuts; -} - -static GtkWidget* -mug_statusbar(void) -{ - GtkWidget* statusbar; - - statusbar = gtk_statusbar_new(); - - return statusbar; -} - -static void -on_query_changed(MugQueryBar* bar, const char* query, MugData* mugdata) -{ - int count; - - /* clear the old message */ - mug_msg_view_set_msg(MUG_MSG_VIEW(mugdata->msgview), NULL); - - count = mug_msg_list_view_query(MUG_MSG_LIST_VIEW(mugdata->mlist), query); - if (count >= 0) { - gchar* msg = - g_strdup_printf("%d message%s found matching '%s'", - count, - count > 1 ? "s" : "", - mug_msg_list_view_get_query(MUG_MSG_LIST_VIEW(mugdata->mlist))); - gtk_statusbar_push(GTK_STATUSBAR(mugdata->statusbar), 0, msg); - g_free(msg); - - mug_msg_list_view_move_first(MUG_MSG_LIST_VIEW(mugdata->mlist)); - gtk_widget_grab_focus(GTK_WIDGET(mugdata->mlist)); - } - - if (count == 0) /* nothing found */ - mug_query_bar_grab_focus(MUG_QUERY_BAR(bar)); -} - -static void -on_msg_selected(MugMsgListView* mlist, const char* mpath, MugData* mugdata) -{ - mug_msg_view_set_msg(MUG_MSG_VIEW(mugdata->msgview), mpath); -} - -static void -on_list_view_error(MugMsgListView* mlist, MugError err, MugData* mugdata) -{ - GtkWidget* errdialog; - const char* msg; - - switch (err) { - case MUG_ERROR_XAPIAN_NOT_UPTODATE: - msg = "The Xapian Database has the wrong version\n" - "Please run 'mu init'"; - break; - case MUG_ERROR_XAPIAN_DIR: - msg = "Cannot find the Xapian database dir\n" - "Please restart mug with --muhome=... pointing\n" - "to your mu home directory"; - break; - case MUG_ERROR_QUERY: msg = "Error in query"; break; - default: msg = "Some error occurred"; break; - } - - errdialog = gtk_message_dialog_new(GTK_WINDOW(mugdata->win), - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "%s", - msg); - - gtk_dialog_run(GTK_DIALOG(errdialog)); - gtk_widget_destroy(errdialog); - - if (err == MUG_ERROR_QUERY) - mug_query_bar_grab_focus(MUG_QUERY_BAR(mugdata->querybar)); -} - -static GtkWidget* -mug_querybar(void) -{ - GtkWidget* querybar; - - querybar = mug_query_bar_new(); - - return querybar; -} - -static GtkWidget* -mug_query_area(MugData* mugdata) -{ - GtkWidget *queryarea, *paned, *scrolled; - - queryarea = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); - paned = gtk_paned_new(GTK_ORIENTATION_VERTICAL); - - mugdata->mlist = mug_msg_list_view_new(mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB)); - scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - gtk_container_add(GTK_CONTAINER(scrolled), mugdata->mlist); - gtk_paned_add1(GTK_PANED(paned), scrolled); - - mugdata->msgview = mug_msg_view_new(); - mug_msg_view_set_note(MUG_MSG_VIEW(mugdata->msgview), - "

Welcome to mug!


" - "mug is an experimental UI for mu, which will " - "slowly evolve into something useful.

Enjoy the ride."); - g_signal_connect(G_OBJECT(mugdata->mlist), - "msg-selected", - G_CALLBACK(on_msg_selected), - mugdata); - g_signal_connect(G_OBJECT(mugdata->mlist), - "error-occured", - G_CALLBACK(on_list_view_error), - mugdata); - gtk_paned_add2(GTK_PANED(paned), mugdata->msgview); - - mugdata->querybar = mug_querybar(); - g_signal_connect(G_OBJECT(mugdata->querybar), - "query-changed", - G_CALLBACK(on_query_changed), - mugdata); - - gtk_box_pack_start(GTK_BOX(queryarea), mugdata->querybar, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(queryarea), paned, TRUE, TRUE, 2); - - gtk_widget_show_all(queryarea); - return queryarea; -} - -static GtkWidget* -mug_main_area(MugData* mugdata) -{ - GtkWidget *mainarea, *w; - - mainarea = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); - - w = mug_shortcuts_bar(mugdata); - gtk_box_pack_start(GTK_BOX(mainarea), w, FALSE, FALSE, 0); - gtk_widget_show(w); - - w = mug_query_area(mugdata); - gtk_box_pack_start(GTK_BOX(mainarea), w, TRUE, TRUE, 0); - gtk_widget_show(w); - - return mainarea; -} - -static GtkWidget* -mug_shell(MugData* mugdata) -{ - GtkWidget* vbox; - - mugdata->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(mugdata->win), "Mug Mail Search"); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); - - mugdata->toolbar = mug_toolbar(mugdata); - gtk_box_pack_start(GTK_BOX(vbox), mugdata->toolbar, FALSE, FALSE, 2); - gtk_box_pack_start(GTK_BOX(vbox), mug_main_area(mugdata), TRUE, TRUE, 2); - - mugdata->statusbar = mug_statusbar(); - gtk_box_pack_start(GTK_BOX(vbox), mugdata->statusbar, FALSE, FALSE, 2); - - gtk_container_add(GTK_CONTAINER(mugdata->win), vbox); - gtk_widget_show_all(vbox); - - gtk_window_set_default_size(GTK_WINDOW(mugdata->win), 700, 500); - gtk_window_set_resizable(GTK_WINDOW(mugdata->win), TRUE); - - { - gchar* icon; - icon = g_strdup_printf("%s%cmug.svg", MUGDIR, G_DIR_SEPARATOR); - gtk_window_set_icon_from_file(GTK_WINDOW(mugdata->win), icon, NULL); - g_free(icon); - } - - return mugdata->win; -} - -static gint -on_focus_query_bar(GtkWidget* ignored, GdkEventKey* event, MugData* mugdata) -{ - if (event->type == GDK_KEY_RELEASE && event->keyval == GDK_KEY_Escape) { - mug_query_bar_grab_focus(MUG_QUERY_BAR(mugdata->querybar)); - return 1; - } - return 0; -} - -int -main(int argc, char* argv[]) -{ - MugData mugdata; - GtkWidget* mugshell; - GOptionContext* octx; - GOptionEntry entries[] = { - {"muhome", - 0, - 0, - G_OPTION_ARG_FILENAME, - &mugdata.muhome, - "specify an alternative mu directory", - NULL}, - {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} /* sentinel */ - }; - - gtk_init(&argc, &argv); - - octx = g_option_context_new("- mug options"); - g_option_context_add_main_entries(octx, entries, "Mug"); - - memset(&mugdata, 0, sizeof(MugData)); - if (!g_option_context_parse(octx, &argc, &argv, NULL)) { - g_option_context_free(octx); - g_printerr("mug: error in options\n"); - return 1; - } - - g_option_context_free(octx); - mu_runtime_init(mugdata.muhome, "mug", FALSE); - - mugshell = mug_shell(&mugdata); - g_signal_connect(G_OBJECT(mugshell), "destroy", G_CALLBACK(gtk_main_quit), NULL); - g_signal_connect(G_OBJECT(mugshell), - "key_release_event", - G_CALLBACK(on_focus_query_bar), - (gpointer)&mugdata); - - gtk_widget_show(mugshell); - mug_query_bar_grab_focus(MUG_QUERY_BAR(mugdata.querybar)); - - gtk_main(); - g_free(mugdata.muhome); - - mu_runtime_uninit(); - - return 0; -} diff --git a/toys/mug/mug.svg b/toys/mug/mug.svg deleted file mode 100644 index b2ddb5c0..00000000 --- a/toys/mug/mug.svg +++ /dev/null @@ -1,443 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - -