"Fossies" - the Fresh Open Source Software Archive

Member "audacious-3.10.1/src/libaudgui/status.cc" (26 Dec 2018, 4043 Bytes) of package /linux/misc/audacious-3.10.1.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "status.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * status.c
    3  * Copyright 2014 John Lindgren
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions are met:
    7  *
    8  * 1. Redistributions of source code must retain the above copyright notice,
    9  *    this list of conditions, and the following disclaimer.
   10  *
   11  * 2. Redistributions in binary form must reproduce the above copyright notice,
   12  *    this list of conditions, and the following disclaimer in the documentation
   13  *    provided with the distribution.
   14  *
   15  * This software is provided "as is" and without any warranty, express or
   16  * implied. In no event shall the authors be liable for any damages arising from
   17  * the use of this software.
   18  */
   19 
   20 #include <gtk/gtk.h>
   21 
   22 #include <libaudcore/hook.h>
   23 #include <libaudcore/i18n.h>
   24 
   25 #include "internal.h"
   26 #include "libaudgui-gtk.h"
   27 
   28 static GtkWidget * progress_window;
   29 static GtkWidget * progress_label, * progress_label_2;
   30 static GtkWidget * error_window, * info_window;
   31 
   32 static void create_progress_window ()
   33 {
   34     progress_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   35     gtk_window_set_type_hint ((GtkWindow *) progress_window, GDK_WINDOW_TYPE_HINT_DIALOG);
   36     gtk_window_set_title ((GtkWindow *) progress_window, _("Working ..."));
   37     gtk_window_set_resizable ((GtkWindow *) progress_window, false);
   38     gtk_container_set_border_width ((GtkContainer *) progress_window, 6);
   39 
   40     GtkWidget * vbox = gtk_vbox_new (false, 6);
   41     gtk_container_add ((GtkContainer *) progress_window, vbox);
   42 
   43     progress_label = gtk_label_new (nullptr);
   44     gtk_label_set_width_chars ((GtkLabel *) progress_label, 40);
   45     gtk_label_set_max_width_chars ((GtkLabel *) progress_label, 40);
   46     gtk_label_set_ellipsize ((GtkLabel *) progress_label, PANGO_ELLIPSIZE_MIDDLE);
   47     gtk_box_pack_start ((GtkBox *) vbox, progress_label, false, false, 0);
   48 
   49     progress_label_2 = gtk_label_new (nullptr);
   50     gtk_label_set_width_chars ((GtkLabel *) progress_label_2, 40);
   51     gtk_label_set_max_width_chars ((GtkLabel *) progress_label_2, 40);
   52     gtk_label_set_ellipsize ((GtkLabel *) progress_label, PANGO_ELLIPSIZE_MIDDLE);
   53     gtk_box_pack_start ((GtkBox *) vbox, progress_label_2, false, false, 0);
   54 
   55     gtk_widget_show_all (progress_window);
   56 
   57     g_signal_connect (progress_window, "destroy",
   58      (GCallback) gtk_widget_destroyed, & progress_window);
   59 }
   60 
   61 static void show_progress (void * data, void * user)
   62 {
   63     if (! progress_window)
   64         create_progress_window ();
   65 
   66     gtk_label_set_text ((GtkLabel *) progress_label, (const char *) data);
   67 }
   68 
   69 static void show_progress_2 (void * data, void * user)
   70 {
   71     if (! progress_window)
   72         create_progress_window ();
   73 
   74     gtk_label_set_text ((GtkLabel *) progress_label_2, (const char *) data);
   75 }
   76 
   77 static void hide_progress (void * data, void * user)
   78 {
   79     if (progress_window)
   80         gtk_widget_destroy (progress_window);
   81 }
   82 
   83 static void show_error (void * data, void * user)
   84 {
   85     audgui_simple_message (& error_window, GTK_MESSAGE_ERROR, _("Error"), (const char *) data);
   86 }
   87 
   88 static void show_info (void * data, void * user)
   89 {
   90     audgui_simple_message (& info_window, GTK_MESSAGE_INFO, _("Information"), (const char *) data);
   91 }
   92 
   93 void status_init ()
   94 {
   95     hook_associate ("ui show progress", show_progress, nullptr);
   96     hook_associate ("ui show progress 2", show_progress_2, nullptr);
   97     hook_associate ("ui hide progress", hide_progress, nullptr);
   98     hook_associate ("ui show error", show_error, nullptr);
   99     hook_associate ("ui show info", show_info, nullptr);
  100 }
  101 
  102 void status_cleanup ()
  103 {
  104     hook_dissociate ("ui show progress", show_progress);
  105     hook_dissociate ("ui show progress 2", show_progress_2);
  106     hook_dissociate ("ui hide progress", hide_progress);
  107     hook_dissociate ("ui show error", show_error);
  108     hook_dissociate ("ui show info", show_info);
  109 
  110     if (progress_window)
  111         gtk_widget_destroy (progress_window);
  112     if (error_window)
  113         gtk_widget_destroy (error_window);
  114     if (info_window)
  115         gtk_widget_destroy (info_window);
  116 }