This file is indexed.

/usr/share/pyshared/dmedia/gtkui/firstrun.py is in dmedia-gtk 0.6.0~repack-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env python

# Authors:
#   David Green <david4dev@gmail.com>
#   Jason Gerard DeRose <jderose@novacut.com>
#
# dmedia: distributed media library
# Copyright (C) 2010 Jason Gerard DeRose <jderose@novacut.com>
#
# This file is part of `dmedia`.
#
# `dmedia` is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# `dmedia` 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 Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with `dmedia`.  If not, see <http://www.gnu.org/licenses/>.

import os
from os import path
from xml.sax import saxutils
from gettext import gettext as _

from gi.repository import Gtk, Pango, GConf


NO_DIALOG = '/apps/dmedia/dont-show-import-firstrun'
conf = GConf.Client.get_default()


TITLE = _('DMedia Importer')

ICON_SIZE = Gtk.IconSize.LARGE_TOOLBAR
PADDING = 5


class EasyBox(object):
    """
    A more convenient box borrowed from TymeLapse.
    """
    def _pack(self, widget, expand=False, padding=PADDING, end=False):
        method = (self.pack_start if not end else self.pack_end)
        method(widget, expand, expand, padding)
        return widget


class VBox(Gtk.VBox, EasyBox):
    pass


class HBox(Gtk.HBox, EasyBox):
    pass


class Label(Gtk.Label):
    """
    A more convenient label borrowed from TymeLapse.
    """
    def __init__(self, text, *tags):
        super(Label, self).__init__()
        self.set_alignment(0, 0.5)
        self.set_padding(5, 5)
        self._text = text
        self._tags = set(tags)
        self._update()
        #self.set_selectable(True)

    def _add_tags(self, *tags):
        self._tags.update(tags)
        self._update()

    def _remove_tags(self, *tags):
        for tag in tags:
            if tag in self._tags:
                self._tags.remove(tag)
        self._update()

    def _set_text(self, text):
        self._text = text
        self._update()

    def _update(self):
        text = ('' if self._text is None else self._text)
        if text and self._tags:
            m = saxutils.escape(text)
            for tag in self._tags:
                m = '<%(tag)s>%(m)s</%(tag)s>' % dict(tag=tag, m=m)
            self.set_markup(m)
        else:
            self.set_text(text)


class Button(Gtk.Button):
    def __init__(self, stock=None, text=None):
        super(Button, self).__init__()
        hbox = HBox()
        self.add(hbox)
        self._image = Gtk.Image()
        self._label = Label(None)
        hbox._pack(self._image)
        hbox._pack(self._label, expand=True)
        if stock is not None:
            self._set_stock(stock)
        if text is not None:
            self._set_text(text)

    def _set_stock(self, stock, size=ICON_SIZE):
        self._image.set_from_stock(stock, size)

    def _set_text(self, text):
        self._label.set_text(text)


class FolderChooser(Button):
    def __init__(self):
        super(FolderChooser, self).__init__(stock=Gtk.STOCK_OPEN)
        self._label.set_ellipsize(Pango.EllipsizeMode.START)
        self._title = _('Choose folder to import...')
        self.connect('clicked', self._on_clicked)
        self._set_value(os.environ['HOME'])

    def _set_value(self, value):
        self._value = path.abspath(value)
        self._label._set_text(self._value)

    def _on_clicked(self, button):
        dialog = Gtk.FileChooserDialog(
            title=self._title,
            action=Gtk.FileChooserAction.SELECT_FOLDER,
            buttons=(
                Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                Gtk.STOCK_OPEN, Gtk.ResponseType.OK,
            ),
        )
        dialog.set_current_folder(self._value)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            self._set_value(dialog.get_filename())
        dialog.destroy()


def okay_button():
    return Button(Gtk.STOCK_OK, _('OK, Import Files'))


class ImportDialog(Gtk.Window):
    def __init__(self):
        super(ImportDialog, self).__init__()
        self.set_default_size(425, 200)
        self.set_title(TITLE)
        try:
            self.set_icon_from_file('/usr/share/pixmaps/dmedia.svg')
        except:
            pass
        self.connect('destroy', Gtk.main_quit)

        self._value = None

        hbox = HBox()
        self.add(hbox)

        vbox = VBox()
        hbox._pack(vbox, expand=True)

        vbox._pack(Label(_('Choose Folder:'), 'b'))
        self._folder = FolderChooser()
        vbox._pack(self._folder)

        self._button = okay_button()
        vbox._pack(self._button, end=True)
        self._button.connect('clicked', self._on_clicked)

        self.show_all()

    def run(self):
        Gtk.main()
        return self._value

    def _on_clicked(self, button):
        self._value = self._folder._value
        Gtk.main_quit()


class FirstRunGUI(Gtk.Window):
    """
    Promt use first time dmedia importer is run.

    For example:

    >>> from dmedia.gtkui.firstrun import FirstRunGUI
    >>> run = FirstRunGUI.run_if_first_run('/media/EOS_DIGITAL')  #doctest: +SKIP
    """

    def __init__(self):
        super(FirstRunGUI, self).__init__()
        self.set_default_size(425, 200)

        self.set_title(TITLE)
        try:
            self.set_icon_from_file('/usr/share/pixmaps/dmedia.svg')
        except:
            pass

        self.ok_was_pressed = False

        self.add_content()

        self.connect_signals()

    def add_content(self):
        vbox = VBox()
        self.add(vbox)

        label1 = Label(_('Welcome to the dmedia importer!'), 'big')
        label1.set_alignment(0.5, 0.5)
        vbox._pack(label1)

        label2 = Label(_('It will import all files in the following folder:'))
        vbox._pack(label2)

        self.folder = Label(None, 'b')
        self.folder.set_ellipsize(Pango.EllipsizeMode.START)
        vbox._pack(self.folder)

        self.dont_show_again = Gtk.CheckButton(label=_("Don't show this again"))
        self.dont_show_again.set_active(True)

        self.ok = okay_button()

        hbox = HBox()
        hbox._pack(self.ok, expand=True)
        hbox._pack(self.dont_show_again)

        vbox._pack(hbox, end=True)


    def connect_signals(self):
        self.connect("delete_event", self.delete_event)
        self.connect("destroy", self.destroy)
        self.ok.connect("clicked", self.on_ok)


    def destroy(self, widget, data=None):
        Gtk.main_quit()


    def delete_event(self, widget, event, data=None):
        return False


    def on_ok(self, widget):
        dont_show_again = self.dont_show_again.get_active()
        val = 0
        if dont_show_again:
            val = 1
        conf.set_bool(NO_DIALOG, val)
        self.ok_was_pressed = True
        self.destroy(widget)

    def go(self, folder):
        self.folder._set_text(folder)
        self.show_all()
        Gtk.main()
        return self.ok_was_pressed

    @classmethod
    def run_if_first_run(cls, base, unset=False):
        if unset:
            conf.unset(NO_DIALOG)
        if conf.get_bool(NO_DIALOG):
            return True
        app = cls()
        return app.go(base)