Remove some annoying debug or show once
[gmpc.git] / src / main.c
blob93b30c804e000daedf842e08fe9ad93657a571cc
1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <strings.h>
25 #include <libxml/parser.h>
27 /** Gtk/glib glade stuff */
28 #include <gtk/gtk.h>
30 #include <libmpd/debug_printf.h>
31 /* header files */
32 #include "main.h"
33 #include "playlist3.h"
35 #include "misc.h"
36 #include "advanced-search.h"
37 #include "gmpc_easy_download.h"
39 #include "setup-assistant.h"
41 #include "gmpc-mpddata-model-playlist.h"
42 #include "bug-information.h"
44 #include "pixbuf-cache.h"
45 #include "options.h"
46 #include "preferences.h"
48 #include "plugin-man.h"
49 #include "browsers/playlist3-playlist-editor.h"
51 #ifdef ENABLE_MMKEYS
52 #include "mm-keys.h"
53 #endif
55 #define LOG_DOMAIN "Gmpc"
56 /**
57 * Get revision
59 #include "revision.h"
61 #include "internal-plugins.h"
62 #include "log.h"
63 #include "mpd-easy-commands.h"
65 /**
66 * Global objects that give signals
69 GtkApplication *gmpc_application = NULL;
72 /* gives signal on connection changes, and state changes of mpd.*/
73 GmpcConnection *gmpcconn = NULL;
74 /* Implements, and gives signals on profiles */
75 GmpcProfiles *gmpc_profiles = NULL;
76 /* Implements, and gives signals on meta_data*/
77 GmpcMetaWatcher *gmw = NULL;
78 /* Easy command */
79 GmpcEasyCommand *gmpc_easy_command = NULL;
80 /* Playlist3 messages */
81 Playlist3MessagePlugin *pl3_messages = NULL;
83 /* The playlist backend */
84 GtkTreeModel *playlist = NULL;
86 GObject *paned_size_group = NULL;
87 /**
88 * This flag indicate the requested connection state by the user.
89 * If the user presses disconnect, you don't want to auto-connect anymore.
90 **/
91 int gmpc_connected = FALSE;
93 static void connection_changed_real(
94 GmpcConnection * gmpcconn,
95 MpdObj * mi,
96 int connect,
97 gpointer data);
99 static void gmpc_status_changed_callback_real(
100 GmpcConnection * gmpcconn,
101 MpdObj * mi,
102 ChangedStatusType what,
103 gpointer data);
106 * Define some local functions
109 static void gmpc_easy_command_set_default_entries(void);
110 static void gmpc_mmkeys_connect_signals(GObject *keys);
111 /** handle connection changed */
112 static void connection_changed(MpdObj * mi, int connect, gpointer data);
114 /** Error callback */
115 static int error_callback(MpdObj * mi,
116 int error_id,
117 char *error_msg,
118 gpointer data);
120 /** init stock icons */
121 static void init_stock_icons(void);
124 * the xml fle pointer to the player window
126 static GtkBuilder *xml_password_window = NULL;
127 static int autoconnect_callback(void);
130 * the ID of the autoconnect timeout callback
132 static guint autoconnect_timeout = 0;
135 * The Config object
137 config_obj *config = NULL;
140 * The Connection object
142 MpdObj *connection = NULL;
144 /* Glade prototypes, these would be static otherwise */
145 void send_password(void);
147 static void print_version(void);
151 * Forward libxml errors into GLib.log errors with LibXML error domain
153 static void xml_error_func(void *ctx, const char *msg, ...)
155 va_list ap;
156 va_start(ap, msg);
157 g_logv("LibXML", G_LOG_LEVEL_DEBUG, msg, ap);
158 va_end(ap);
160 /* \todo why is this here? */
161 static xmlGenericErrorFunc handler = (xmlGenericErrorFunc) xml_error_func;
164 static gboolean hide_on_start(void)
166 pl3_hide();
167 return FALSE;
169 static int handle_commandline(GApplication *app, GApplicationCommandLine *cmd, gpointer data)
171 gchar **argv;
172 gint argc;
174 argv = g_application_command_line_get_arguments(cmd, &argc);
175 printf("Commandline handler: %i\n", argc);
176 if(argc > 1) {
177 int i;
178 for ( i = 1; i < argc; i++) {
179 printf("executing: %s\n" , argv[i]);
180 gmpc_easy_command_do_query(gmpc_easy_command, argv[i]);
182 }else {
183 printf("activate\n");
184 if(g_application_get_is_remote(app)) {
185 g_application_activate(gmpc_application);
189 return EXIT_SUCCESS;
193 int main(int argc, char **argv)
195 GdkDisplay *display = NULL;
196 #ifdef WIN32
197 gchar *packagedir = NULL;
198 #endif
199 #ifdef ENABLE_MMKEYS
200 MmKeys *keys = NULL;
201 #endif
203 /* A string used severall times to create a path */
204 gchar *url = NULL;
206 INIT_TIC_TAC();
208 log_init();
211 * Setup NLS
213 #ifdef ENABLE_NLS
214 g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Setting NLS");
215 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
216 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
217 textdomain(GETTEXT_PACKAGE);
218 #endif
220 //gtk_set_locale();
221 // setlocale();
223 TEC("Setting up locale");
225 parse_options(&argc, &argv);
227 /* Show the version, if requested */
228 if (settings.show_version)
230 print_version();
231 return EXIT_SUCCESS;
233 TEC("Parsing command line options");
235 log_set_debug_level(settings.debug_level);
236 TEC("Set debug level")
237 /* Show the bug-information dialog */
238 if (settings.show_bug_information)
240 bug_information_file_new(stdout);
241 return EXIT_SUCCESS;
246 * Init libxml.
247 * Libxml is not used (directly) by gmpc.
248 * But via glade and several plugins use it.
249 * I need to initialize it before the threading is started.
250 * So moved to gmpc.
252 * This fixes the plugin crasher bug on windows.
254 xmlInitParser();
255 initGenericErrorDefaultFunc(&handler);
258 * Check if threading is supported, if so, start it.
259 * Don't fail here, stuff like can cause that it is allready initialized.
261 if (!g_thread_supported())
262 g_thread_init(NULL);
264 TEC("Initializing threading");
266 * initialize gtk
268 g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Initializing gtk ");
270 #ifdef WIN32
272 * This loads an extra gtk rc file on windows.
273 * This is used to re-enable rule-hint in the treeview.
274 * (this is forced off on windows).
276 packagedir = g_win32_get_package_installation_directory_of_module(NULL);
277 url = g_build_filename(packagedir,
278 "share", "gmpc",
279 "gmpc-gtk-win32.rc", NULL);
280 q_free(packagedir);
281 gtk_rc_add_default_file(url);
282 g_free(url);
283 #endif
286 /* initialize gtk */
287 gmpc_application = gtk_application_new("org.gmpclient.gmpc", G_APPLICATION_HANDLES_COMMAND_LINE);
288 /* Get Display */
289 display = gdk_display_get_default ();
291 GError *error = NULL;
294 if(!g_application_register(G_APPLICATION(gmpc_application),NULL, &error))
296 g_error("Failed to register instance: %s", error->message);
297 return EXIT_FAILURE;
300 // Check if we are already running.
301 if(g_application_get_is_remote(G_APPLICATION(gmpc_application)))
303 g_debug("Already running....");
304 return g_application_run(G_APPLICATION(gmpc_application), argc, argv);
307 g_signal_connect(G_OBJECT(gmpc_application), "command-line", G_CALLBACK(handle_commandline), NULL);
308 g_signal_connect(G_OBJECT(gmpc_application), "activate", G_CALLBACK(pl3_show_and_position_window), NULL);
310 TEC("Gtk init");
314 GError *error = NULL;
315 GtkCssProvider *provider = gtk_css_provider_new ();
316 gchar *path = g_build_filename(PACKAGE_DATA_DIR, "gmpc", "gmpc.css", NULL);
318 gtk_css_provider_load_from_path(provider, path, &error);
320 printf("Loading: %s\n", path);
323 if(error != NULL) {
324 g_error("Failed to load css file: %s:%s",path, error->message);
325 g_free(path);
326 g_error_free(error);
328 GdkScreen *screen = gdk_display_get_default_screen (display);
330 gtk_style_context_add_provider_for_screen (
331 screen, GTK_STYLE_PROVIDER (provider),
332 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
334 g_object_unref (provider);
335 g_free(path);
339 /* Hack to override the icon theme, on recursive zeltak request */
340 if(settings.icon_theme != NULL) {
341 gtk_settings_set_string_property(gtk_settings_get_default(),
342 "gtk-icon-theme-name" , settings.icon_theme,NULL);
346 * Call create_gmpc_paths();
347 * This function checks if the path needed path are available
348 * and creates them if needed.
350 create_gmpc_paths();
351 TEC("Check version and create paths");
355 * Open the config file
358 * Check if the user has forced a different config file location.
359 * else set to ~/.gmpc/gmpc.cfg
361 if (!settings.config_path)
363 url = gmpc_get_user_path("gmpc.cfg");
364 } else
366 url = g_strdup(settings.config_path);
370 * Open it
372 g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
373 "Trying to open the config file: %s", url);
374 config = cfg_open(url);
377 * Show gtk error message and quit if config failed to open.
379 if (config == NULL)
381 g_log(LOG_DOMAIN, G_LOG_LEVEL_ERROR,
382 "Failed to save/load configuration:\n%s\n", url);
383 show_error_message(_("Failed to load the configuration system."));
384 return EXIT_FAILURE;
386 TEC("Opening config file: %s", url);
387 q_free(url);
390 * \TODO, Check if version changed, then say something about it
392 * Enable this function if we need todo some upgrading on version change.
393 * Removal of this current content destroys config conversion from 0.17 and
394 * up
396 url = cfg_get_single_value_as_string(config, "Default", "version");
397 if (url == NULL || strcmp(url, VERSION))
399 cfg_set_single_value_as_string(config, "Default", "version", VERSION);
401 if (url) q_free(url);
402 TEC("New version check");
405 if (settings.quit)
407 cfg_close(config);
408 return EXIT_SUCCESS;
411 /* Easy command */
412 gmpc_easy_command = gmpc_easy_command_new();
413 TEC("Init easy command")
414 gmpc_easy_command_set_default_entries();
415 TEC("Set easy commands")
416 mpd_easy_commands_init();
417 TEC("Set MPD Easy commands");
418 /* Advanced search */
419 advanced_search_init();
420 TEC("Init advanced search");
422 /* PanedSizeGroup */
423 paned_size_group = (GObject *) gmpc_paned_size_group_new();
425 gmpc_profiles = gmpc_profiles_new();
426 /* If user requested a profile, look it up and set it active */
427 if (settings.profile_name)
429 gmpc_profiles_set_profile_from_name(gmpc_profiles,
430 settings.profile_name);
432 TEC("Setting up gmpc idle,signals and profiles");
434 * Initialize the new metadata subsystem.
436 meta_data_init();
438 TEC("Initializing metadata system");
439 pixbuf_cache_create();
440 TEC("Pixbuf cache create()");
443 * stock icons
445 g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading stock icons");
446 init_stock_icons();
447 TEC("Init stock icons");
449 * Create connection object
451 connection = mpd_new_default();
452 if (connection == NULL)
455 * if failed, print error message
457 g_log(LOG_DOMAIN,
458 G_LOG_LEVEL_ERROR,
459 "Failed to create connection object\n");
460 show_error_message(_("Failed to setup libmpd"));
461 abort();
463 TEC("Setting up mpd connection object");
465 * Connect signals to the connection object
467 mpd_signal_connect_status_changed(connection,
468 GmpcStatusChangedCallback, NULL);
469 mpd_signal_connect_error(connection,
470 error_callback, NULL);
471 mpd_signal_connect_connection_changed(connection,
472 connection_changed, NULL);
474 * Just some trick to provide glib signals
476 gmpcconn = (GmpcConnection *) gmpc_connection_new();
477 g_signal_connect(G_OBJECT(gmpcconn),
478 "connection_changed",
479 G_CALLBACK(connection_changed_real), NULL);
480 g_signal_connect(G_OBJECT(gmpcconn),
481 "status_changed",
482 G_CALLBACK(gmpc_status_changed_callback_real), NULL);
484 TEC("Setting up mpd object signal system");
486 * New Metadata object
488 gmw = gmpc_meta_watcher_new();
489 TEC("Initializing metadata watcher");
493 /** init the error messages */
494 pl3_messages = playlist3_message_plugin_new();
496 playlist = (GtkTreeModel*)gmpc_mpddata_model_playlist_new(
497 gmpcconn,
498 connection);
499 gmpc_mpddata_model_disable_image(GMPC_MPDDATA_MODEL(playlist));
502 * Add the internall plugins
504 plugin_manager_load_internal_plugins();
508 * load dynamic plugins
510 if (!settings.disable_plugins)
512 plugin_manager_load_plugins();
516 * Create the main window
518 create_playlist3();
519 TEC("Creating playlist window");
521 /* time todo some initialisation of plugins */
522 plugin_manager_initialize_plugins();
525 * First run dialog
527 * If gmpc is ran for the first time, we want to show a wizard that helps
528 * the user getting started.
530 if (cfg_get_single_value_as_int_with_default(config,
531 "Default",
532 "first-run",
535 setup_assistant();
536 cfg_set_single_value_as_int(config, "Default", "first-run", 0);
537 TEC("Setup first run assistant");
541 * If autoconnect is enabled, tell gmpc that it's in state it should connect
543 if (cfg_get_single_value_as_int_with_default(config,
544 "connection",
545 "autoconnect",
546 DEFAULT_AUTOCONNECT))
548 gmpc_connected = TRUE;
551 * create timeouts
552 * get the status every 1/2 second should be enough, but it's configurable.
554 g_timeout_add(cfg_get_single_value_as_int_with_default(config,
555 "connection",
556 "mpd-update-speed",
557 500), (GSourceFunc) update_mpd_status, NULL);
559 * create the autoconnect timeout,
560 * if autoconnect enable, it will check every 5 seconds
561 * if you are still connected, and reconnects you if not.
563 autoconnect_timeout = g_timeout_add_seconds(5,
564 (GSourceFunc) autoconnect_callback, NULL);
567 * Call this when entering the main loop,
568 * so you are connected on startup, not 5 seconds later
570 g_idle_add((GSourceFunc) autoconnect_callback, NULL);
571 if (settings.fullscreen)
573 g_idle_add((GSourceFunc) pl3_window_fullscreen, NULL);
577 * If the user wants gmpc to be started hidden,
578 * call pl3_hide after the mainloop started running
580 if (cfg_get_single_value_as_int_with_default(config,
581 "Default",
582 "start-hidden",
583 FALSE) ||
584 settings.start_hidden)
586 g_timeout_add(250, (GSourceFunc) hide_on_start, NULL);
588 TEC("Setting up timers");
590 #ifdef ENABLE_MMKEYS
591 if (GDK_IS_X11_DISPLAY(display))
594 * Setup Multimedia Keys
596 keys = mmkeys_new();
597 gmpc_mmkeys_connect_signals(G_OBJECT(keys));
598 TEC("Setting up multimedia keys");
600 #endif
602 url = gmpc_get_user_path("gmpc.key");
603 gtk_accel_map_load(url);
604 q_free(url);
608 * run the main loop
610 //gtk_main();
611 int retv = g_application_run(G_APPLICATION(gmpc_application), argc, argv);
614 * Shutting Down
615 * cleaning up.
617 url = gmpc_get_user_path("gmpc.key");
618 gtk_accel_map_save(url);
619 q_free(url);
621 /* Quit _all_ downloads */
622 gmpc_easy_async_quit();
624 /* tell the plugins to save themself. */
625 plugin_manager_save_state();
627 /* Should fix some possible crashes */
628 gtk_tree_view_set_model(playlist3_get_category_tree_view(), NULL);
631 * Clear metadata struct
633 meta_data_destroy();
635 /* time todo some destruction of plugins */
636 plugin_manager_destroy_plugins();
638 playlist3_destroy();
640 g_object_unref(playlist);
641 g_object_unref(G_OBJECT(gmw));
643 /* Destroy PanedSizeGroup */
644 g_object_unref(paned_size_group);
646 * Close the config file
648 TOC("Starting save config");
649 cfg_close(config);
650 TOC("Saved config");
651 g_object_unref(gmpc_profiles);
652 g_object_unref(gmpcconn);
654 pixbuf_cache_destroy();
656 * This now gets destroyed with the plugins
658 advanced_search_destroy();
660 * Destroy the connection object
662 mpd_free(connection);
664 /* Reset xml error function and cleanup */
665 initGenericErrorDefaultFunc((xmlGenericErrorFunc *) NULL);
666 xmlCleanupParser();
667 /* cleanup */
669 g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Quit....\n");
670 return retv;
675 * Function to quiet the program
677 void main_quit(void)
679 g_log(LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Quiting gmpc....");
681 * close playlist and store size
683 pl3_hide();
685 * Remove the autoconnect timeout,
687 if (autoconnect_timeout)
688 g_source_remove(autoconnect_timeout);
691 * Call the connection changed.
692 * so it saves the playlist pos
694 mpd_signal_connect_connection_changed(connection, NULL, NULL);
697 * Disconnect when connected
699 if (mpd_check_connected(connection))
701 if (cfg_get_single_value_as_int_with_default(config,
702 "connection", "stop-on-exit", FALSE))
704 mpd_player_stop(connection);
706 mpd_disconnect(connection);
709 * Exit main loop
711 gtk_widget_destroy(playlist3_get_window());
716 * Callback that get's called every 5 seconds,
717 * and tries to autoconnect
718 * (when enabled)
721 static int autoconnect_backoff = 0;
722 static int autoconnect_callback(void)
724 /* Don't autoconnect while showing the first start assistant */
725 if (setup_assistant_is_running())
726 return FALSE;
728 /* check if there is an connection. */
729 if (!mpd_check_connected(connection))
731 /* connect when autoconnect is enabled, the user wants to be connected
733 if (gmpc_connected
734 && cfg_get_single_value_as_int_with_default(config,
735 "connection", "autoconnect", DEFAULT_AUTOCONNECT))
737 connect_to_mpd();
740 if (autoconnect_backoff < 60)
741 autoconnect_backoff += 1;
742 /* keep the timeout running */
743 if (autoconnect_timeout)
744 g_source_remove(autoconnect_timeout);
745 autoconnect_timeout = g_timeout_add_seconds(5 + autoconnect_backoff,
746 (GSourceFunc) autoconnect_callback, NULL);
747 return FALSE;
751 static void init_stock_icons(void)
753 char *path;
755 path = gmpc_get_full_image_path();
756 gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), path);
757 q_free(path);
759 gtk_window_set_default_icon_name("gmpc");
761 #ifdef WIN32
762 /* The Windows gtkrc sets this to 0, so images don't work on buttons */
763 gtk_settings_set_long_property(gtk_settings_get_default(),
764 "gtk-button-images", TRUE, "main");
765 #endif
767 return;
772 * Handle status changed callback from the libmpd object
773 * This involves propegating the signal
775 void GmpcStatusChangedCallback(MpdObj * mi,
776 ChangedStatusType what,
777 void *userdata)
779 g_signal_emit_by_name(gmpcconn, "status-changed", mi, what);
783 /* The actual handling of the status changed signal */
784 static void gmpc_status_changed_callback_real(GmpcConnection * conn,
785 MpdObj * mi,
786 ChangedStatusType what,
787 gpointer data)
789 /* When permission changes, update the advanced search regex */
790 if (what & MPD_CST_PERMISSION)
792 advanced_search_update_taglist();
795 * Make the plugins recieve the signals
797 plugin_manager_status_changed(mi, what);
801 /*******************************
802 * Error handling
803 * TODO: Needs to be redone/rethought
806 static void password_dialog_response(
807 GtkWidget * dialog,
808 gint response,
809 gpointer data)
811 gchar *path;
812 switch (response)
814 case 0:
815 return;
816 case GTK_RESPONSE_OK:
818 path = (char *)gtk_entry_get_text(
819 GTK_ENTRY(gtk_builder_get_object(xml_password_window,
820 "pass_entry")));
821 mpd_set_password(connection, path);
822 if (gtk_toggle_button_get_active
823 (GTK_TOGGLE_BUTTON(gtk_builder_get_object(
824 xml_password_window,
825 "ck_save_pass"))))
827 connection_set_password(path);
829 mpd_send_password(connection);
831 break;
832 default:
833 if (mpd_server_check_command_allowed(connection, "status") !=
834 MPD_SERVER_COMMAND_ALLOWED)
836 playlist3_show_error_message(
837 _("GMPC has insufficient permissions on the mpd server."),
838 ERROR_CRITICAL);
839 mpd_disconnect(connection);
841 break;
843 gtk_widget_destroy(
844 (GtkWidget *) gtk_builder_get_object(xml_password_window,
845 "password-dialog"));
846 g_object_unref(xml_password_window);
847 xml_password_window = NULL;
851 static void password_dialog(int failed)
853 GtkWidget *pl3_win = playlist3_get_window();
854 gchar *path = NULL;
855 if (xml_password_window)
856 return;
857 path = gmpc_get_full_glade_path("password-dialog.ui");
858 xml_password_window = gtk_builder_new();
859 gtk_builder_add_from_file(xml_password_window, path, NULL);
860 gtk_window_set_transient_for(GTK_WINDOW
861 (gtk_builder_get_object(xml_password_window, "password-dialog")),
862 GTK_WINDOW(pl3_win));
863 q_free(path);
864 if (!xml_password_window)
865 return;
866 if (failed)
868 path = g_strdup_printf(
869 _("Failed to set password on: '%s'\nPlease try again"),
870 mpd_get_hostname(connection));
871 } else
873 path = g_strdup_printf(
874 _("Please enter your password for: '%s'"),
875 mpd_get_hostname(connection));
877 gtk_label_set_text(
878 GTK_LABEL(gtk_builder_get_object(xml_password_window, "pass_label")),
879 path);
880 q_free(path);
882 g_signal_connect(G_OBJECT
883 (gtk_builder_get_object
884 (xml_password_window, "password-dialog")), "response",
885 G_CALLBACK(password_dialog_response), xml_password_window);
889 void send_password(void)
891 password_dialog(FALSE);
894 static int error_callback(MpdObj * mi,
895 int error_id,
896 char *error_msg,
897 gpointer data)
899 int autoconnect = cfg_get_single_value_as_int_with_default(config,
900 "connection",
901 "autoconnect",
902 DEFAULT_AUTOCONNECT);
904 /* if we are not connected we show a reconnect */
905 if (!mpd_check_connected(mi))
907 GtkWidget *button;
908 char *str;
909 /* no response? then we just ignore it when autoconnecting. */
910 if (error_id == 15 && autoconnect)
911 return FALSE;
913 str = g_markup_printf_escaped("<b>%s %i: %s</b>",
914 _("error code"),
915 error_id,
916 error_msg);
917 playlist3_show_error_message(str, ERROR_CRITICAL);
918 button = gtk_button_new_from_stock(GTK_STOCK_CONNECT);
919 g_signal_connect(G_OBJECT(button),
920 "clicked",
921 G_CALLBACK(connect_to_mpd), NULL);
922 playlist3_error_add_widget(button);
923 g_free(str);
924 } else
926 if (setup_assistant_is_running()
927 && (error_id == MPD_ACK_ERROR_PERMISSION ||
928 error_id == MPD_ACK_ERROR_PASSWORD))
930 gchar *str = g_markup_printf_escaped("<b>%s</b>",
931 _("Insufficient permission to connect to mpd. Check password"));
932 setup_assistant_set_error(str);
933 q_free(str);
934 return TRUE;
936 if(error_id == MPD_ACK_ERROR_SYSTEM || error_id == MPD_ACK_ERROR_NO_EXIST) {
937 if(g_regex_match_simple(".*{.*playlist.*}.*", error_msg,
938 0,G_REGEX_MATCH_NOTEMPTY))
940 static int show_once = 0;
941 if(show_once) return FALSE;
942 show_once = 1;
943 GtkWidget *button = NULL;
944 if(favorites != NULL) {
945 gmpc_favorites_list_set_disable(favorites,TRUE);
947 playlist_editor_set_disabled();
948 playlist3_show_error_message(
949 _("Playlist support in MPD is not working. See the "
950 "manual on possible fixes.\n"
951 "Playlist editor and favorites are now disabled."
953 , ERROR_WARNING);
955 return FALSE;
958 if (error_id == MPD_ACK_ERROR_PASSWORD)
960 password_dialog(TRUE);
961 } else if (error_id == MPD_ACK_ERROR_PERMISSION)
963 password_dialog(FALSE);
964 } else
966 gchar *str = g_markup_printf_escaped("<b>%s %i: %s</b>",
967 _("error code"), error_id,
968 error_msg);
969 playlist3_show_error_message(str, ERROR_CRITICAL);
970 g_free(str);
973 return FALSE;
978 * handle a connection changed
980 static void connection_changed(MpdObj * mi, int connected, gpointer data)
982 /* propagate the signal to the connection object */
983 if (mpd_check_connected(mi) != connected)
985 g_log(LOG_DOMAIN,
986 G_LOG_LEVEL_ERROR,
987 "Connection state differs from actual state: act: %i\n",
988 !connected);
991 * Check version
993 if (connected && !mpd_server_check_version(mi, 0, 13, 0))
995 gchar *value = g_markup_printf_escaped("<b>%s</b>",
996 _("MPD versions before 0.13.0 are not supported"));
997 /* disable user connect ! */
998 gmpc_connected = FALSE;
999 mpd_disconnect(mi);
1000 /* Give error */
1001 playlist3_show_error_message(value, ERROR_CRITICAL);
1002 g_free(value);
1004 /* Remove timeout */
1005 if (connected)
1007 if (autoconnect_timeout)
1008 g_source_remove(autoconnect_timeout);
1009 autoconnect_timeout = 0;
1010 autoconnect_backoff = 0;
1012 if (connected)
1014 advanced_search_update_taglist();
1017 * force an update of status, to check password
1019 if (connected)
1021 mpd_status_update(mi);
1022 if (connected != mpd_check_connected(mi))
1024 g_log(LOG_DOMAIN, G_LOG_LEVEL_WARNING, "State differs, exit");
1025 /* Probly disconnected when getting status.. exiting */
1026 return;
1030 /* remove this when it does not fix it */
1031 g_signal_emit_by_name(gmpcconn,
1032 "connection-changed",
1034 mpd_check_connected(mi));
1038 static void connection_changed_real(
1039 GmpcConnection * obj,
1040 MpdObj * mi,
1041 int connected,
1042 gpointer data)
1045 * propegate signals
1047 g_log(LOG_DOMAIN,
1048 G_LOG_LEVEL_DEBUG,
1049 "Connection changed %i-%i \n",
1050 connected,
1051 mpd_check_connected(mi));
1052 plugin_manager_connection_changed(mi, connected);
1055 * force an update of status
1057 if (connected)
1058 mpd_status_update(mi);
1060 if (connected)
1062 playlist3_show_error_message(_("Connected to mpd"), ERROR_INFO);
1063 } else
1065 playlist3_show_error_message(_("Disconnected from mpd"), ERROR_INFO);
1068 if (!connected)
1070 if (autoconnect_timeout)
1071 g_source_remove(autoconnect_timeout);
1072 autoconnect_timeout = g_timeout_add_seconds(5,
1073 (GSourceFunc) autoconnect_callback, NULL);
1074 autoconnect_backoff = 0;
1080 * Shows an error message.
1082 void show_error_message(const gchar * string)
1084 GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL,
1085 GTK_DIALOG_MODAL,
1086 GTK_MESSAGE_ERROR,
1087 GTK_BUTTONS_CLOSE,
1088 "%s", string);
1089 gtk_widget_show(dialog);
1090 gtk_dialog_run(GTK_DIALOG(dialog));
1093 static void print_version(void)
1095 printf("%s\n", _("Gnome Music Player Client"));
1096 printf(GMPC_COPYRIGHT "\n\n");
1097 printf("%-25s: %s\n", _("Tagline"), GMPC_TAGLINE);
1098 printf("%-25s: %i.%i.%i\n", _("Version"),
1099 GMPC_MAJOR_VERSION,
1100 GMPC_MINOR_VERSION,
1101 GMPC_MICRO_VERSION);
1102 if (revision && revision[0] != '\0')
1104 printf("%-25s: %s\n", _("Revision"), revision);
1109 * Set a basic set of easycommand handlers.
1111 static void gmpc_easy_command_set_default_entries(void)
1113 gmpc_easy_command_add_entry_stock_id(gmpc_easy_command,
1114 _("quit"), "",
1115 _("Quit gmpc"),
1116 (GmpcEasyCommandCallback *) main_quit,
1117 NULL,GTK_STOCK_QUIT);
1119 gmpc_easy_command_add_entry(gmpc_easy_command,
1120 _("hide"), "",
1121 _("Hide gmpc"),
1122 (GmpcEasyCommandCallback *) pl3_hide,
1123 NULL);
1125 gmpc_easy_command_add_entry(gmpc_easy_command,
1126 _("show"), "",
1127 _("Show gmpc"),
1128 (GmpcEasyCommandCallback *) create_playlist3,
1129 NULL);
1131 gmpc_easy_command_add_entry(gmpc_easy_command,
1132 _("toggle"), "",
1133 _("Toggle gmpc visibility"),
1134 (GmpcEasyCommandCallback *) pl3_toggle_hidden,
1135 NULL);
1137 gmpc_easy_command_add_entry(gmpc_easy_command,
1138 _("show notification"), "",
1139 _("Show trayicon notification"),
1140 (GmpcEasyCommandCallback *) tray_icon2_create_tooltip,
1141 NULL);
1142 gmpc_easy_command_add_entry_stock_id(gmpc_easy_command,
1143 _("preferences"), "",
1144 _("Show preferences window"),
1145 (GmpcEasyCommandCallback *) create_preferences_window,
1146 NULL, GTK_STOCK_PREFERENCES);
1148 gmpc_easy_command_add_entry(gmpc_easy_command,
1149 _("bug information"), "",
1150 _("Show bug information"),
1151 (GmpcEasyCommandCallback *) bug_information_window_new,
1152 NULL);
1154 gmpc_easy_command_add_entry_icon_name(gmpc_easy_command,
1155 _("url"), "",
1156 _("Show add url window"),
1157 (GmpcEasyCommandCallback *) url_start,
1158 NULL,"add-url");
1160 gmpc_easy_command_add_entry_icon_name(gmpc_easy_command,
1161 _("url"), ".*://.*",
1162 _("Add url <scheme>://<path>"),
1163 (GmpcEasyCommandCallback *) url_start_easy_command,
1164 NULL,"add-url");
1167 static void gmpc_mmkeys_connect_signals(GObject *keys)
1169 g_signal_connect(keys,
1170 "mm_playpause",
1171 G_CALLBACK(play_song), NULL);
1173 g_signal_connect(keys,
1174 "mm_play",
1175 G_CALLBACK(real_play_song), NULL);
1177 g_signal_connect(keys,
1178 "mm_pause",
1179 G_CALLBACK(real_pause_song), NULL);
1181 g_signal_connect(keys,
1182 "mm_next",
1183 G_CALLBACK(next_song), NULL);
1185 g_signal_connect(keys,
1186 "mm_prev",
1187 G_CALLBACK(prev_song), NULL);
1189 g_signal_connect(keys,
1190 "mm_stop",
1191 G_CALLBACK(stop_song), NULL);
1193 g_signal_connect(keys,
1194 "mm_fastforward",
1195 G_CALLBACK(song_fastforward), NULL);
1197 g_signal_connect(keys,
1198 "mm_fastbackward",
1199 G_CALLBACK(song_fastbackward), NULL);
1201 g_signal_connect(keys,
1202 "mm_repeat",
1203 G_CALLBACK(repeat_toggle), NULL);
1205 g_signal_connect(keys,
1206 "mm_random",
1207 G_CALLBACK(random_toggle), NULL);
1209 g_signal_connect(keys,
1210 "mm_raise",
1211 G_CALLBACK(create_playlist3), NULL);
1213 g_signal_connect(keys,
1214 "mm_hide",
1215 G_CALLBACK(pl3_hide), NULL);
1217 g_signal_connect(keys,
1218 "mm_toggle_hidden",
1219 G_CALLBACK(pl3_toggle_hidden), NULL);
1221 g_signal_connect(keys,
1222 "mm_volume_up",
1223 G_CALLBACK(volume_up), NULL);
1225 g_signal_connect(keys,
1226 "mm_volume_down",
1227 G_CALLBACK(volume_down), NULL);
1229 g_signal_connect(keys,
1230 "mm_toggle_mute",
1231 G_CALLBACK(volume_toggle_mute), NULL);
1233 g_signal_connect(keys,
1234 "mm_show_notification",
1235 G_CALLBACK(tray_icon2_create_tooltip), NULL);
1237 g_signal_connect_swapped(keys,
1238 "mm_show_easy_command",
1239 G_CALLBACK(gmpc_easy_command_popup),
1240 gmpc_easy_command);
1243 /* vim: set noexpandtab ts=4 sw=4 sts=4 tw=80: */