~ubuntu-branches/ubuntu/natty/awn-extras/natty

« back to all changes in this revision

Viewing changes to applets/maintained/showdesktop/applet.vala

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-12-18 21:14:11 UTC
  • Revision ID: james.westby@ubuntu.com-20101218211411-hp9b0h7xhnu5o3kp
Tags: upstream-0.4.1~bzr1485
Import upstream version 0.4.1~bzr1485

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Show/hide desktop applet written in Vala.
 
3
 *
 
4
 * Copyright (C) 2009 Mark Lee <avant-wn@lazymalevolence.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
19
 *
 
20
 * Author : Mark Lee <avant-wn@lazymalevolence.com>
 
21
 */
 
22
 
 
23
using Awn;
 
24
 
 
25
class ShowDesktop : AppletSimple
 
26
{
 
27
  private const string[] authors = {
 
28
    "Mark Lee <avant-wn@lazymalevolence.com>"
 
29
  };
 
30
  private Gtk.Menu _menu;
 
31
 
 
32
  public ShowDesktop (string canonical_name, string uid, int panel_id)
 
33
  {
 
34
    unowned Wnck.Screen screen;
 
35
 
 
36
    GLib.Object (canonical_name: canonical_name,
 
37
                 uid: uid,
 
38
                 panel_id: panel_id);
 
39
 
 
40
    this.display_name = Gettext._ ("Show Desktop");
 
41
    this.clicked.connect (this.on_clicked);
 
42
    this.context_menu_popup.connect (this.on_context_menu_popup);
 
43
 
 
44
    screen = Wnck.Screen.get_default ();
 
45
    screen.showing_desktop_changed.connect (this.on_show_desktop_changed);
 
46
    this.on_show_desktop_changed (screen);
 
47
 
 
48
    this.map_event.connect (this.on_map_event);
 
49
  }
 
50
 
 
51
  private bool
 
52
  on_map_event (Gdk.Event event)
 
53
  {
 
54
    Awn.Tooltip tooltip = (this.get_icon () as Awn.Icon).get_tooltip ();
 
55
    tooltip.toggle_on_click = false;
 
56
    return true;
 
57
  }
 
58
 
 
59
  private void
 
60
  on_clicked ()
 
61
  {
 
62
    unowned Wnck.Screen screen;
 
63
 
 
64
    screen = Wnck.Screen.get_default ();
 
65
    screen.toggle_showing_desktop (!screen.get_showing_desktop ());
 
66
  }
 
67
 
 
68
  private void
 
69
  on_context_menu_popup (Gdk.EventButton event)
 
70
  {
 
71
    if (this._menu == null)
 
72
    {
 
73
      Gtk.Widget about_item;
 
74
 
 
75
      this._menu = this.create_default_menu () as Gtk.Menu;
 
76
      about_item = this.create_about_item ("Copyright © 2009 Mark Lee",
 
77
                                           AppletLicense.GPLV2, Build.VERSION,
 
78
                                           Gettext._ ("Hides your windows and shows your desktop."),
 
79
                                           null, null, "user-desktop",
 
80
                                           null, authors, null, null);
 
81
      about_item.show ();
 
82
      this._menu.append (about_item as Gtk.MenuItem);
 
83
    }
 
84
    this._menu.set_screen (null);
 
85
    this.get_icon ().popup_gtk_menu (this._menu, event.button, event.time);
 
86
  }
 
87
 
 
88
  private void
 
89
  on_show_desktop_changed (Wnck.Screen screen)
 
90
  {
 
91
    if (screen.get_showing_desktop ())
 
92
    {
 
93
      this.set_tooltip_text (Gettext._ ("Show hidden windows"));
 
94
      this.set_icon_name ("view-restore");
 
95
    }
 
96
    else
 
97
    {
 
98
      this.set_tooltip_text (Gettext._ ("Hide windows and show desktop"));
 
99
      this.set_icon_name ("user-desktop");
 
100
    }
 
101
  }
 
102
}
 
103
 
 
104
public Applet
 
105
awn_applet_factory_initp (string canonical_name, string uid, int panel_id)
 
106
{
 
107
  Intl.setlocale (LocaleCategory.ALL, "");
 
108
  Gettext.bindtextdomain (Build.GETTEXT_PACKAGE, Build.LOCALEDIR);
 
109
  Gettext.textdomain (Build.GETTEXT_PACKAGE);
 
110
  return new ShowDesktop (canonical_name, uid, panel_id);
 
111
}
 
112
 
 
113
// vim:ft=vala:et:ts=2 sts=2 sw=2:ai:cindent