~ubuntu-branches/ubuntu/raring/gnome-sushi/raring

« back to all changes in this revision

Viewing changes to src/js/viewers/folder.js

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-07-17 10:39:33 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120717103933-8smu9yvdkm9f7ro2
Tags: 0.5.4-0ubuntu1
* New upstream release
* debian/control:
  - Bump build-depends on libclutter-1.0-dev
  - Add build-depends on libfreetype6-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2011 Red Hat, Inc.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public License as
6
 
 * published by the Free Software Foundation; either version 2 of the
7
 
 * License, or (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful, but
10
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 * General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
 
 * 02111-1307, USA.
18
 
 *
19
 
 * The Sushi project hereby grant permission for non-gpl compatible GStreamer
20
 
 * plugins to be used and distributed together with GStreamer and Sushi. This
21
 
 * permission is above and beyond the permissions granted by the GPL license
22
 
 * Sushi is covered by.
23
 
 *
24
 
 * Authors: Cosimo Cecchi <cosimoc@redhat.com>
25
 
 *
26
 
 */
27
 
 
28
 
let MimeHandler = imports.ui.mimeHandler;
29
 
let Gtk = imports.gi.Gtk;
30
 
let Sushi = imports.gi.Sushi;
31
 
 
32
 
let Gettext = imports.gettext.domain('sushi');
33
 
let _ = Gettext.gettext;
34
 
 
35
 
let Constants = imports.util.constants;
36
 
let Utils = imports.ui.utils;
37
 
 
38
 
function FolderRenderer(args) {
39
 
    this._init(args);
40
 
}
41
 
 
42
 
FolderRenderer.prototype = {
43
 
    _init : function() {
44
 
        this._folderLoader = null;
45
 
        this._folderLoaderId = 0;
46
 
 
47
 
        this.moveOnClick = true;
48
 
        this.canFullScreen = false;
49
 
    },
50
 
 
51
 
    prepare : function(file, mainWindow, callback) {
52
 
        this._mainWindow = mainWindow;
53
 
        this._file = file;
54
 
        this._callback = callback;
55
 
 
56
 
        this.lastWidth = 0;
57
 
        this.lastHeight = 0;
58
 
 
59
 
        this._folderLoader = new Sushi.FileLoader();
60
 
        this._folderLoader.file = file;
61
 
        this._folderLoaderId =
62
 
            this._folderLoader.connect('notify',
63
 
                                       Lang.bind(this, this._onFolderInfoChanged));
64
 
 
65
 
        this._box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
66
 
                                  spacing: 6 });
67
 
        this._image = new Gtk.Image({ icon_name: 'folder',
68
 
                                      pixel_size: 256 });
69
 
        this._box.pack_start(this._image, false, false, 0);
70
 
 
71
 
        let vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
72
 
                                 spacing: 1,
73
 
                                 margin_top: 48,
74
 
                                 margin_left: 12,
75
 
                                 margin_right: 12 });
76
 
        this._box.pack_start(vbox, false, false, 0);
77
 
 
78
 
        let hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
79
 
                                 spacing: 6 });
80
 
        vbox.pack_start(hbox, false, false, 0);
81
 
 
82
 
        this._titleLabel = new Gtk.Label();
83
 
        this._titleLabel.set_halign(Gtk.Align.START);
84
 
        hbox.pack_start(this._titleLabel, false, false, 0);
85
 
 
86
 
        this._spinner = new Gtk.Spinner();
87
 
        hbox.pack_start(this._spinner, false, false, 0);
88
 
        this._spinner.start();
89
 
 
90
 
        this._sizeLabel = new Gtk.Label();
91
 
        this._sizeLabel.set_halign(Gtk.Align.START);
92
 
        vbox.pack_start(this._sizeLabel, false, false, 0);
93
 
 
94
 
        this._dateLabel = new Gtk.Label();
95
 
        this._dateLabel.set_halign(Gtk.Align.START);
96
 
        vbox.pack_start(this._dateLabel, false, false, 0);
97
 
 
98
 
        this._applyLabels();
99
 
 
100
 
        this._box.show_all();
101
 
        this._actor = new GtkClutter.Actor({ contents: this._box });
102
 
 
103
 
        this._callback();
104
 
    },
105
 
 
106
 
    render : function() {
107
 
        return this._actor;
108
 
    },
109
 
 
110
 
    _applyLabels : function() {
111
 
        let name = this._folderLoader.name;
112
 
        if (!name) {
113
 
            try {
114
 
                name = this._folderLoader.file.get_basename();
115
 
            } catch (e) {
116
 
                name = '';
117
 
            }
118
 
        }
119
 
        let titleStr =
120
 
            '<b><big>' + name + '</big></b>';
121
 
 
122
 
        let sizeStr =
123
 
            '<small><b>' + _("Size") + '  </b>' +
124
 
            ((this._folderLoader.size) ? (this._folderLoader.size) : (_("Loading...")))
125
 
             + '</small>';
126
 
 
127
 
        let dateStr =
128
 
            '<small><b>' + _("Modified") + '  </b>' +
129
 
             ((this._folderLoader.time) ? (this._folderLoader.time) : (_("Loading...")))
130
 
             + '</small>';
131
 
 
132
 
        this._titleLabel.set_markup(titleStr);
133
 
        this._sizeLabel.set_markup(sizeStr);
134
 
        this._dateLabel.set_markup(dateStr);
135
 
    },
136
 
 
137
 
    _onFolderInfoChanged : function() {
138
 
        if (!this._folderLoader.get_loading()) {
139
 
            this._spinner.stop();
140
 
            this._spinner.hide();
141
 
        }
142
 
 
143
 
        this._applyLabels();
144
 
        this._image.set_from_pixbuf(this._folderLoader.icon);
145
 
        this._mainWindow.refreshSize();
146
 
    },
147
 
 
148
 
    clear : function() {
149
 
        if (this._folderLoader) {
150
 
            this._folderLoader.disconnect(this._folderLoaderId);
151
 
            this._folderLoaderId = 0;
152
 
 
153
 
            this._folderLoader.stop();
154
 
            this._folderLoader = null;
155
 
        }
156
 
    },
157
 
 
158
 
    getSizeForAllocation : function(allocation) {
159
 
        return Utils.getStaticSize(this, this._box);
160
 
    }
161
 
}
162
 
 
163
 
let handler = new MimeHandler.MimeHandler();
164
 
let renderer = new FolderRenderer();
165
 
 
166
 
handler.registerMime('inode/directory', renderer);