summaryrefslogtreecommitdiff
path: root/src/mi-app.vala
blob: f38d70164a1453027d538c39a96dd955ceadc135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* GStreamer media browser
 * Copyright (C) 2010 Stefan Kost <ensonic@user.sf.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Steet,
 * Boston, MA 02110-1301, USA.
 */

using Gtk;
using MediaInfo;

public class MediaInfo.App : Window
{
  private FileChooserWidget chooser;
  private Info info;

  public string directory { get; set; }

  public App(string? directory)
  {
    GLib.Object (type :  WindowType.TOPLEVEL);
    this.directory = directory;

    // configure the window
    set_title (_("GStreamer Media Info"));
    set_default_size (500, 350);
    try {
      set_default_icon_from_file (Config.PKGDATADIR + "/ui/icons/gst-mi.png");
    } catch (Error e) {
      debug ("Application icon missing: %s: %s", e.domain.to_string (), e.message);
    }
    destroy.connect (Gtk.main_quit);

    VBox vbox = new VBox( false, 0);
    add (vbox);

    // add a menubar
    vbox.pack_start (create_menu(), false, false, 0);

    HPaned paned = new HPaned ();
    paned.set_border_width (0);
    vbox.pack_start (paned, true, true, 3);

    // add a file-chooser with info pane as preview widget
    chooser = new FileChooserWidget (FileChooserAction.OPEN);
    paned.pack1 (chooser, true, true);

    if (directory != null) {
      //chooser.set_current_folder (GLib.Environment.get_home_dir ());
      chooser.set_current_folder (directory);
    }
    chooser.set_show_hidden (false);
    chooser.selection_changed.connect (on_update_preview);

    info = new Info ();
    paned.pack2 (info, true, true);
  }

  // helper

  private MenuBar create_menu ()
  {
    MenuBar menu_bar = new MenuBar ();
    MenuItem item;
    Menu sub_menu;
    AccelGroup accel_group;

    accel_group = new AccelGroup ();
    this.add_accel_group (accel_group);

    item = new MenuItem.with_label (_("File"));
    menu_bar.append (item);

    sub_menu = new Menu ();
    item.set_submenu (sub_menu);

    // TODO: add "open uri" item
    // -> dialog with text entry (pre-file with clipboard content)
    // -> discover that uri and clear selection in browser

    item = new ImageMenuItem.from_stock (STOCK_QUIT, accel_group);
    sub_menu.append (item);
    item.activate.connect (Gtk.main_quit);

    item = new MenuItem.with_label (_("View"));
    //item.set_accel_path ("<GstMi-Main>/MainMenu/View");
    menu_bar.append (item);

    sub_menu = new Menu ();
    item.set_submenu (sub_menu);

    CheckMenuItem citem = new CheckMenuItem.with_label (_("Full Screen"));
    // see http://bugzilla.gnome.org/show_bug.cgi?id=551184
    // FIXME: we're also not getting a proper accelerator shown in the menu item
    citem.add_accelerator("activate", accel_group, Gdk.keyval_from_name ("F11"), 0, 0);
    //citem.set_accel_path ("<GstMi-Main>/MainMenu/View/FullScreen");
    //AccelMap.add_entry ("<GstMi-Main>/MainMenu/View/FullScreen", 0xffc8, 0);

    sub_menu.append (citem);
    citem.toggled.connect (on_fullscreen_toggled);

    // add "help" menu with "about" item
    item = new MenuItem.with_label (_("Help"));
    menu_bar.append (item);

    sub_menu = new Menu ();
    item.set_submenu (sub_menu);

    item = new ImageMenuItem.from_stock (STOCK_ABOUT, accel_group);
    sub_menu.append (item);
    item.activate.connect (on_about_clicked);

    return (menu_bar);
  }

  // signal handler

  private void on_update_preview ()
  {
    File file = chooser.get_file();
    bool res = false;

    if (file != null && file.query_file_type (FileQueryInfoFlags.NONE, null) == FileType.REGULAR) {
      res = info.discover (chooser.get_uri());
    }
    chooser.set_preview_widget_active (res);
  }

  private void on_fullscreen_toggled (CheckMenuItem item)
  {
    if (item.active) {
      fullscreen();
    } else {
      unfullscreen();
    }
  }

  private void on_about_clicked (MenuItem item)
  {
    AboutDialog dlg = new AboutDialog ();

    dlg.set_version(Config.PACKAGE_VERSION);
    dlg.set_program_name("GStreamer Media Info");
    dlg.set_comments(_("Quickly browse, play and analyze media files."));
    dlg.set_copyright("Stefan Kost <ensonic@users.sf.net>");
    dlg.run();
    dlg.hide();
  }
}