~matttbe/ubuntu/quantal/lxpanel/lp1013171

« back to all changes in this revision

Viewing changes to src/plugins/volumealsa/volumealsa.c

  • Committer: Package Import Robot
  • Author(s): Julien Lavergne
  • Date: 2012-02-13 23:40:40 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20120213234040-w24ouhodotl76yav
Tags: 0.5.8+git20120212-0ubuntu1
* New upstream snapshot
 - Run dialog opens up in the background (LP: #889414)
 - Abiliy to configure task Bar Font (LP: #690662)
 - Volume applet uses wrong icon (LP: #878117)
 - Add ability for lxpanel sound applet to launch a GUI for sound management
   (LP: #692276)
 - lxpanel indicator support can't be configured (LP: #692260)
 - Task Bar (Window List) - Options on 64bit version are different than 32bit
   version (LP: #909127)
* debian/patches
 - indicator-support.patch: Remove, merged upstream.
 - fix_indicator_dir.patch: Remove, merged upstream.
 - fix_position.patch: Remove, merged upstream.
 - missing_glades.patch: Remove, fixed upstream.
 - default-config.patch: Refresh.
 - configure_desktop_number.patch: Refresh.
 - 99_refresh_autotools.patch: Refresh.
* debian/control:
 - Build-depends on libwnck-dev.
* debian/lxpanel.install:
 - Add new plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "plugin.h"
31
31
#include "dbg.h"
32
32
 
33
 
#define ICONS_VOLUME PACKAGE_DATA_DIR "/lxpanel/images/volume.png"
34
 
#define ICONS_MUTE PACKAGE_DATA_DIR "/lxpanel/images/mute.png"
 
33
#define ICONS_VOLUME_HIGH   PACKAGE_DATA_DIR "/lxpanel/images/volume-high.png"
 
34
#define ICONS_VOLUME_MEDIUM PACKAGE_DATA_DIR "/lxpanel/images/volume-medium.png"
 
35
#define ICONS_VOLUME_LOW    PACKAGE_DATA_DIR "/lxpanel/images/volume-low.png"
 
36
#define ICONS_MUTE          PACKAGE_DATA_DIR "/lxpanel/images/mute.png"
35
37
 
36
38
typedef struct {
37
39
 
228
230
{
229
231
    /* Mute status. */
230
232
    gboolean mute = asound_is_muted(vol);
 
233
    int level = asound_get_volume(vol);
231
234
    
232
 
    if ( ! panel_image_set_icon_theme(vol->plugin->panel, vol->tray_icon, ((mute) ? "audio-volume-muted" : "audio-volume-high")))
233
 
    {
234
 
         panel_image_set_from_file(vol->plugin->panel, vol->tray_icon, ((mute) ? ICONS_MUTE : ICONS_VOLUME));
 
235
    /* Change icon according to mute / volume */
 
236
    const char* icon="audio-volume-muted";
 
237
    const char* icon_fallback=ICONS_MUTE;
 
238
    if (mute)
 
239
    {
 
240
         icon="audio-volume-muted";
 
241
         icon_fallback=ICONS_MUTE;
 
242
    }
 
243
    else if (level >= 75)
 
244
    {
 
245
         icon="audio-volume-high";
 
246
         icon_fallback=ICONS_VOLUME_HIGH;
 
247
    }
 
248
    else if (level >= 50)
 
249
    {
 
250
         icon="audio-volume-medium";
 
251
         icon_fallback=ICONS_VOLUME_MEDIUM;
 
252
    }
 
253
    else if (level > 0)
 
254
    {
 
255
         icon="audio-volume-low";
 
256
         icon_fallback=ICONS_VOLUME_LOW;
 
257
    }
 
258
 
 
259
    /* Change icon, fallback to default icon if theme doesn't exsit */
 
260
    if ( ! panel_image_set_icon_theme(vol->plugin->panel, vol->tray_icon, icon))
 
261
    {
 
262
         panel_image_set_from_file(vol->plugin->panel, vol->tray_icon, icon_fallback);
235
263
    }
236
264
 
237
265
    g_signal_handler_block(vol->mute_check, vol->mute_check_handler);
240
268
    g_signal_handler_unblock(vol->mute_check, vol->mute_check_handler);
241
269
 
242
270
    /* Volume. */
243
 
    int level = asound_get_volume(vol);
244
271
    if (vol->volume_scale != NULL)
245
272
    {
246
273
        g_signal_handler_block(vol->volume_scale, vol->volume_scale_handler);
455
482
    g_free(vol);
456
483
}
457
484
 
 
485
/* Callback when the configuration dialog is to be shown. */
 
486
 
 
487
static void volumealsa_configure(Plugin * p, GtkWindow * parent)
 
488
{
 
489
 
 
490
    GdkScreen *screen = gdk_screen_get_default();
 
491
    GError *error = NULL;
 
492
    const gchar *command_line = NULL;
 
493
 
 
494
    if (g_find_program_in_path("pulseaudio"))
 
495
    {
 
496
     /* Assume that when pulseaudio is installed, it's launching every time */
 
497
        if (g_find_program_in_path("gnome-sound-applet"))
 
498
        {
 
499
            command_line = "gnome-sound-applet";
 
500
        }
 
501
        else
 
502
        {
 
503
            if (g_find_program_in_path("pavucontrol"))
 
504
            {
 
505
                command_line = "pavucontrol";
 
506
            }
 
507
        }
 
508
    }
 
509
 
 
510
    /* Fallback to alsamixer when PA is not running, or when no PA utility is find */
 
511
    if (command_line == NULL)
 
512
    {
 
513
        if (g_find_program_in_path("gnome-alsamixer"))
 
514
        {
 
515
            command_line = "gnome-alsamixer";
 
516
        }
 
517
        else
 
518
        {
 
519
            if (g_find_program_in_path("alsamixer"))
 
520
            {
 
521
                if (g_find_program_in_path("xterm"))
 
522
                {
 
523
                    command_line = "xterm -e alsamixer";
 
524
                }
 
525
            }
 
526
        }
 
527
    }
 
528
 
 
529
    if (command_line)
 
530
    {
 
531
        gdk_spawn_command_line_on_screen(screen,
 
532
                                         command_line,
 
533
                                         &error);
 
534
    }
 
535
    else
 
536
    {
 
537
 
 
538
        GtkWidget* msg;
 
539
 
 
540
        msg = gtk_message_dialog_new( NULL,
 
541
                                      0,
 
542
                                      GTK_MESSAGE_ERROR,
 
543
                                      GTK_BUTTONS_OK,
 
544
                                      (_("Error, you need to install a application to configure the sound (pavucontol, alsamixer ...)")) );
 
545
        gtk_dialog_run( GTK_DIALOG(msg) );
 
546
        gtk_widget_destroy( msg );
 
547
 
 
548
    }
 
549
 
 
550
    if (error)
 
551
    {
 
552
        g_print("%s\n", error->message);
 
553
        g_free (error);
 
554
    }
 
555
 
 
556
}
 
557
 
458
558
/* Callback when panel configuration changes. */
459
559
static void volumealsa_panel_configuration_changed(Plugin * p)
460
560
{
474
574
 
475
575
    constructor : volumealsa_constructor,
476
576
    destructor  : volumealsa_destructor,
477
 
    config : NULL,
 
577
    config :volumealsa_configure,
478
578
    save : NULL,
479
579
    panel_configuration_changed : volumealsa_panel_configuration_changed
480
580