| 1 |
# Copyright 2014 (C) Raster Software Vigo (Sergio Costas) |
| 2 |
# |
| 3 |
# This file is part of DeVeDe-NG |
| 4 |
# |
| 5 |
# DeVeDe-NG is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 3 |
| 7 |
# as published by the Free Software Foundation. |
| 8 |
# |
| 9 |
# DeVeDe-NG is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU 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, see <http://www.gnu.org/licenses/> |
| 16 |
|
| 17 |
from gi.repository import Gtk |
| 18 |
import os |
| 19 |
import devedeng.configuration_data |
| 20 |
|
| 21 |
class add_files: |
| 22 |
|
| 23 |
last_path = None |
| 24 |
|
| 25 |
def __init__(self): |
| 26 |
|
| 27 |
self.config = devedeng.configuration_data.configuration.get_config() |
| 28 |
|
| 29 |
def run(self): |
| 30 |
|
| 31 |
builder = Gtk.Builder() |
| 32 |
builder.set_translation_domain(self.config.gettext_domain) |
| 33 |
|
| 34 |
builder.add_from_file(os.path.join(self.config.glade, "wadd_files.ui")) |
| 35 |
builder.connect_signals(self) |
| 36 |
wadd_files = builder.get_object("add_files") |
| 37 |
self.wfile_chooser = builder.get_object("filechooserwidget1") |
| 38 |
if (add_files.last_path is not None): |
| 39 |
self.wfile_chooser.set_current_folder(add_files.last_path) |
| 40 |
self.wbutton_accept = builder.get_object("button_accept") |
| 41 |
|
| 42 |
file_filter_videos = Gtk.FileFilter() |
| 43 |
file_filter_videos.set_name(_("Video files")) |
| 44 |
file_filter_videos.add_mime_type("video/*") |
| 45 |
file_filter_videos.add_pattern("*.rmvb") |
| 46 |
|
| 47 |
file_filter_all = Gtk.FileFilter() |
| 48 |
file_filter_all.set_name(_("All files")) |
| 49 |
file_filter_all.add_pattern("*") |
| 50 |
|
| 51 |
self.wfile_chooser.add_filter(file_filter_videos) |
| 52 |
self.wfile_chooser.add_filter(file_filter_all) |
| 53 |
|
| 54 |
wadd_files.show_all() |
| 55 |
|
| 56 |
retval = wadd_files.run() |
| 57 |
self.files = None |
| 58 |
|
| 59 |
if (retval == 2): |
| 60 |
self.files = self.get_files() |
| 61 |
|
| 62 |
add_files.last_path = self.wfile_chooser.get_current_folder() |
| 63 |
wadd_files.destroy() |
| 64 |
|
| 65 |
if (retval == 2): |
| 66 |
return True |
| 67 |
else: |
| 68 |
return False |
| 69 |
|
| 70 |
def get_files(self): |
| 71 |
files = self.wfile_chooser.get_filenames() |
| 72 |
files_out = [] |
| 73 |
for element in files: |
| 74 |
if (os.path.isdir(element)): |
| 75 |
continue |
| 76 |
files_out.append(element) |
| 77 |
return files_out |
| 78 |
|
| 79 |
def on_filechooserwidget1_selection_changed(self, b): |
| 80 |
|
| 81 |
files = self.get_files() |
| 82 |
if (len(files) == 0): |
| 83 |
self.wbutton_accept.set_sensitive(False) |
| 84 |
else: |
| 85 |
self.wbutton_accept.set_sensitive(True) |