/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
2
#
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
7
#
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
12
#
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
17
import ConfigParser
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
18
import os
19
import os.path
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
20
import sys
21
22
try:
0.8.14 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
23
    import pygtk
24
    pygtk.require("2.0")
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
25
except:
0.8.14 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
26
    pass
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
27
try:
0.8.14 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
28
    import gtk
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
29
    import gtk.gdk
0.8.14 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
30
    import gtk.glade
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
31
except:
0.8.14 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
32
    sys.exit(1)
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
33
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
34
from handler import OliveHandler
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
35
36
# Olive GTK UI version
37
__version__ = '0.1'
38
39
class OliveGtk:
40
    """ The main Olive GTK frontend class. This is called when launching the
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
41
    program. """
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
42
    
43
    def __init__(self):
44
        # Load the glade file
45
        self.gladefile = "/usr/share/olive/olive.glade"
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
46
        if not os.path.exists(self.gladefile):
47
            # Load from current directory if not installed
48
            self.gladefile = "olive.glade"
49
0.8.14 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
50
        self.toplevel = gtk.glade.XML(self.gladefile, 'window_main')
51
        
52
        self.window = self.toplevel.get_widget('window_main')
53
        self.window.show_all()
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
54
        
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
55
        self.pref = OlivePreferences()
56
        self.comm = OliveCommunicator(self.toplevel, self.pref)
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
57
        handler = OliveHandler(self.gladefile, self.comm)
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
58
        
59
        # Dictionary for signal_autoconnect
60
        dic = { "on_window_main_destroy": gtk.main_quit,
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
61
                "on_window_main_delete_event": handler.on_window_main_delete_event,
62
                "on_quit_activate": handler.on_window_main_delete_event,
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
63
                "on_about_activate": handler.on_about_activate,
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
64
                "on_menuitem_add_files_activate": handler.on_menuitem_add_files_activate,
65
                "on_menuitem_remove_file_activate": handler.on_menuitem_remove_file_activate,
0.8.37 by Szilveszter Farkas (Phanatic)
Implemented Make directory functionality; some cleanups.
66
                "on_menuitem_file_make_directory_activate": handler.on_menuitem_file_make_directory_activate,
0.8.38 by Szilveszter Farkas (Phanatic)
Implemented Move functionality; move() backend code refined.
67
                "on_menuitem_file_move_activate": handler.on_menuitem_file_move_activate,
0.8.40 by Szilveszter Farkas (Phanatic)
Implemented Rename functionality.
68
                "on_menuitem_file_rename_activate": handler.on_menuitem_file_rename_activate,
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
69
                "on_menuitem_branch_initialize_activate": handler.on_menuitem_branch_initialize_activate,
0.8.22 by Szilveszter Farkas (Phanatic)
2006-07-31 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
70
                "on_menuitem_branch_get_activate": handler.on_menuitem_branch_get_activate,
71
                "on_menuitem_branch_checkout_activate": handler.on_menuitem_branch_checkout_activate,
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
72
                "on_menuitem_branch_commit_activate": handler.on_menuitem_branch_commit_activate,
73
                "on_menuitem_branch_push_activate": handler.on_menuitem_branch_push_activate,
0.8.36 by Szilveszter Farkas (Phanatic)
Implemented pull functionality.
74
                "on_menuitem_branch_pull_activate": handler.on_menuitem_branch_pull_activate,
0.8.29 by Szilveszter Farkas (Phanatic)
Implemented Status window; some code cleanups.
75
                "on_menuitem_branch_status_activate": handler.on_menuitem_branch_status_activate,
0.8.28 by Szilveszter Farkas (Phanatic)
Statistics menu added
76
                "on_menuitem_stats_diff_activate": handler.on_menuitem_stats_diff_activate,
77
                "on_menuitem_stats_log_activate": handler.not_implemented,
78
                "on_menuitem_stats_infos_activate": handler.not_implemented,
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
79
                "on_toolbutton_update_clicked": handler.not_implemented,
80
                "on_toolbutton_commit_clicked": handler.on_menuitem_branch_commit_activate,
0.8.36 by Szilveszter Farkas (Phanatic)
Implemented pull functionality.
81
                "on_toolbutton_pull_clicked": handler.on_menuitem_branch_pull_activate,
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
82
                "on_toolbutton_push_clicked": handler.on_menuitem_branch_push_activate,
0.8.24 by Szilveszter Farkas (Phanatic)
Implemented context menu for the file list.
83
                "on_treeview_right_button_press_event": handler.on_treeview_right_button_press_event,
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
84
                "on_treeview_right_row_activated": handler.on_treeview_right_row_activated,
85
                "on_treeview_left_button_press_event": handler.on_treeview_left_button_press_event,
86
                "on_treeview_left_row_activated": handler.on_treeview_left_row_activated }
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
87
        
88
        # Connect the signals to the handlers
89
        self.toplevel.signal_autoconnect(dic)
90
        
0.8.41 by Szilveszter Farkas (Phanatic)
Main window preferences (size, position) are stored.
91
        # Apply window size and position
92
        width = self.pref.get_preference('window_width', 'int')
93
        height = self.pref.get_preference('window_height', 'int')
94
        self.window.resize(width, height)
95
        x = self.pref.get_preference('window_x', 'int')
96
        y = self.pref.get_preference('window_y', 'int')
97
        self.window.move(x, y)
98
        # Apply paned position
99
        pos = self.pref.get_preference('paned_position', 'int')
100
        self.comm.hpaned_main.set_position(pos)
101
        
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
102
        # Load default data into the panels
103
        self.treeview_left = self.toplevel.get_widget('treeview_left')
104
        self.treeview_right = self.toplevel.get_widget('treeview_right')
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
105
        self._load_left()
106
        self._load_right()
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
107
        
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
108
    def _load_left(self):
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
109
        """ Load data into the left panel. (Bookmarks) """
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
110
        # set cursor to busy
111
        self.comm.set_busy(self.treeview_left)
112
        
113
        # Create TreeStore
114
        treestore = gtk.TreeStore(str)
115
        
116
        # Get bookmarks
117
        bookmarks = self.comm.pref.get_bookmarks()
118
        
119
        # Add them to the TreeStore
120
        titer = treestore.append(None, ['Bookmarks'])
121
        for item in bookmarks:
122
            treestore.append(titer, [item])
123
        
124
        # Create the column and add it to the TreeView
125
        self.treeview_left.set_model(treestore)
126
        tvcolumn_bookmark = gtk.TreeViewColumn('Bookmark')
127
        self.treeview_left.append_column(tvcolumn_bookmark)
128
        
129
        # Set up the cells
130
        cell = gtk.CellRendererText()
131
        tvcolumn_bookmark.pack_start(cell, True)
132
        tvcolumn_bookmark.add_attribute(cell, 'text', 0)
133
        
134
        # Expand the tree
135
        self.treeview_left.expand_all()
136
        
137
        self.comm.set_busy(self.treeview_left, False)
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
138
        
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
139
    def _load_right(self):
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
140
        """ Load data into the right panel. (Filelist) """
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
141
        import olive.backend.fileops as fileops
142
        
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
143
        # set cursor to busy
144
        self.comm.set_busy(self.treeview_right)
145
        
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
146
        # Create ListStore
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
147
        liststore = gtk.ListStore(str, str, str)
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
148
        
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
149
        dirs = ['..']
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
150
        files = []
151
        
152
        # Fill the appropriate lists
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
153
        path = self.comm.get_path()
0.8.41 by Szilveszter Farkas (Phanatic)
Main window preferences (size, position) are stored.
154
        dotted_files = self.pref.get_preference('dotted_files')
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
155
        for item in os.listdir(path):
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
156
            if not dotted_files and item[0] == '.':
157
                continue
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
158
            if os.path.isdir(path + '/' + item):
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
159
                dirs.append(item)
160
            else:
161
                files.append(item)
162
            
163
        # Sort'em
164
        dirs.sort()
165
        files.sort()
166
        
167
        # Add'em to the ListStore
168
        for item in dirs:    
0.8.17 by Szilveszter Farkas (Phanatic)
2006-07-19 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
169
            liststore.append([gtk.STOCK_DIRECTORY, item, ''])
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
170
        for item in files:
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
171
            liststore.append([gtk.STOCK_FILE, item, fileops.status(path + '/' + item)])
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
172
        
173
        # Create the columns and add them to the TreeView
174
        self.treeview_right.set_model(liststore)
175
        tvcolumn_filename = gtk.TreeViewColumn('Filename')
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
176
        tvcolumn_status = gtk.TreeViewColumn('Status')
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
177
        self.treeview_right.append_column(tvcolumn_filename)
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
178
        self.treeview_right.append_column(tvcolumn_status)
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
179
        
180
        # Set up the cells
0.8.17 by Szilveszter Farkas (Phanatic)
2006-07-19 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
181
        cellpb = gtk.CellRendererPixbuf()
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
182
        cell = gtk.CellRendererText()
0.8.17 by Szilveszter Farkas (Phanatic)
2006-07-19 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
183
        tvcolumn_filename.pack_start(cellpb, False)
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
184
        tvcolumn_filename.pack_start(cell, True)
0.8.17 by Szilveszter Farkas (Phanatic)
2006-07-19 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
185
        tvcolumn_filename.set_attributes(cellpb, stock_id=0)
0.8.12 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
186
        tvcolumn_filename.add_attribute(cell, 'text', 1)
0.8.13 by Szilveszter Farkas (Phanatic)
2006-07-17 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
187
        tvcolumn_status.pack_start(cell, True)
188
        tvcolumn_status.add_attribute(cell, 'text', 2)
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
189
        
190
        # set cursor to default
191
        self.comm.set_busy(self.treeview_right, False)
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
192
193
class OliveCommunicator:
194
    """ This class is responsible for the communication between the different
195
    modules. """
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
196
    def __init__(self, toplevel, pref):
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
197
        # Get glade main component
198
        self.toplevel = toplevel
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
199
        # Preferences object
200
        self.pref = pref
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
201
        # Default path
202
        self._path = os.getcwd()
203
        
204
        # Initialize the statusbar
205
        self.statusbar = self.toplevel.get_widget('statusbar')
206
        self.context_id = self.statusbar.get_context_id('olive')
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
207
        
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
208
        # Get the main window
209
        self.window_main = self.toplevel.get_widget('window_main')
0.8.41 by Szilveszter Farkas (Phanatic)
Main window preferences (size, position) are stored.
210
        # Get the HPaned
211
        self.hpaned_main = self.toplevel.get_widget('hpaned_main')
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
212
        # Get the TreeViews
213
        self.treeview_left = self.toplevel.get_widget('treeview_left')
214
        self.treeview_right = self.toplevel.get_widget('treeview_right')
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
215
    
216
    def set_path(self, path):
217
        """ Set the current path while browsing the directories. """
218
        self._path = path
219
    
220
    def get_path(self):
221
        """ Get the current path. """
222
        return self._path
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
223
    
224
    def get_selected_right(self):
225
        """ Get the selected filename. """
226
        treeselection = self.treeview_right.get_selection()
227
        (model, iter) = treeselection.get_selected()
228
        
229
        if iter is None:
230
            return None
231
        else:
232
            return model.get_value(iter, 1)
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
233
    
234
    def get_selected_left(self):
235
        """ Get the selected bookmark. """
236
        treeselection = self.treeview_left.get_selection()
237
        (model, iter) = treeselection.get_selected()
238
        
239
        if iter is None:
240
            return None
241
        else:
242
            return model.get_value(iter, 0)
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
243
244
    def set_statusbar(self, message):
245
        """ Set the statusbar message. """
246
        self.statusbar.push(self.context_id, message)
247
    
248
    def clear_statusbar(self):
249
        """ Clean the last message from the statusbar. """
250
        self.statusbar.pop(self.context_id)
251
    
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
252
    def refresh_left(self):
253
        """ Refresh the bookmark list. """
254
        # set cursor to busy
255
        self.set_busy(self.treeview_left)
256
        
257
        # Get TreeStore and clear it
258
        treestore = self.treeview_left.get_model()
259
        treestore.clear()
260
        
261
        # Get bookmarks
262
        bookmarks = self.pref.get_bookmarks()
263
        
264
        # Add them to the TreeStore
265
        titer = treestore.append(None, ['Bookmarks'])
266
        for item in bookmarks:
267
            treestore.append(titer, [item])
268
        
269
        # Add the TreeStore to the TreeView
270
        self.treeview_left.set_model(treestore)
271
        
272
        # Expand the tree
273
        self.treeview_left.expand_all()
274
        
275
        self.set_busy(self.treeview_left, False)
276
    
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
277
    def refresh_right(self, path=None):
0.8.15 by Szilveszter Farkas (Phanatic)
2006-07-18 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
278
        """ Refresh the file list. """
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
279
        import olive.backend.fileops as fileops
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
280
        
281
        self.set_busy(self.treeview_right)
282
        
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
283
        if path is None:
284
            path = self.get_path()
0.8.39 by Szilveszter Farkas (Phanatic)
Fixed the double-click Bookmarks bug.
285
        
286
        # A workaround for double-clicking Bookmarks
287
        if not os.path.exists(path):
288
            self.set_busy(self.treeview_right, False)
289
            return
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
290
291
        # Get ListStore and clear it
292
        liststore = self.treeview_right.get_model()
293
        liststore.clear()
294
        
295
        dirs = ['..']
296
        files = []
297
        
298
        # Fill the appropriate lists
0.8.41 by Szilveszter Farkas (Phanatic)
Main window preferences (size, position) are stored.
299
        dotted_files = self.pref.get_preference('dotted_files')
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
300
        for item in os.listdir(path):
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
301
            if not dotted_files and item[0] == '.':
302
                continue
0.8.18 by Szilveszter Farkas (Phanatic)
2006-07-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
303
            if os.path.isdir(path + '/' + item):
304
                dirs.append(item)
305
            else:
306
                files.append(item)
307
            
308
        # Sort'em
309
        dirs.sort()
310
        files.sort()
311
        
312
        # Add'em to the ListStore
313
        for item in dirs:    
314
            liststore.append([gtk.STOCK_DIRECTORY, item, ''])
315
        for item in files:
316
            liststore.append([gtk.STOCK_FILE, item, fileops.status(path + '/' + item)])
317
        
318
        # Add the ListStore to the TreeView
319
        self.treeview_right.set_model(liststore)
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
320
        
321
        self.set_busy(self.treeview_right, False)
322
323
    def set_busy(self, widget, busy=True):
324
        if busy:
325
            widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
326
        else:
327
            widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
328
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
329
        gtk.main_iteration(0)
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
330
331
class OlivePreferences:
332
    """ A class which handles Olive's preferences. """
333
    def __init__(self):
334
        """ Initialize the Preferences class. """
335
        # Some default options
0.8.41 by Szilveszter Farkas (Phanatic)
Main window preferences (size, position) are stored.
336
        self.defaults = { 'strict_commit' : False,
337
                          'dotted_files'  : False,
338
                          'window_width'  : 700,
339
                          'window_height' : 400,
340
                          'window_x'      : 40,
341
                          'window_y'      : 40,
342
                          'paned_position': 200 }
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
343
        
344
        # Create a config parser object
345
        self.config = ConfigParser.RawConfigParser()
346
        
347
        # Load the configuration
348
        if sys.platform == 'win32':
349
            # Windows - no dotted files
350
            self.config.read([os.path.expanduser('~/olive.conf')])
351
        else:
352
            self.config.read([os.path.expanduser('~/.olive.conf')])
353
        
354
    def _get_default(self, option):
355
        """ Get the default option for a preference. """
356
        try:
357
            ret = self.defaults[option]
358
        except KeyError:
359
            return None
360
        else:
361
            return ret
362
363
    def refresh(self):
364
        """ Refresh the configuration. """
365
        # First write out the changes
366
        self.write()
367
        # Then load the configuration again
368
        if sys.platform == 'win32':
369
            # Windows - no dotted files
370
            self.config.read([os.path.expanduser('~/olive.conf')])
371
        else:
372
            self.config.read([os.path.expanduser('~/.olive.conf')])
373
374
    def write(self):
375
        """ Write the configuration to the appropriate files. """
376
        if sys.platform == 'win32':
377
            # Windows - no dotted files
378
            fp = open(os.path.expanduser('~/olive.conf'), 'w')
379
            self.config.write(fp)
380
            fp.close()
381
        else:
382
            fp = open(os.path.expanduser('~/.olive.conf'), 'w')
383
            self.config.write(fp)
384
            fp.close()
385
0.8.41 by Szilveszter Farkas (Phanatic)
Main window preferences (size, position) are stored.
386
    def get_preference(self, option, kind='str'):
387
        """ Get the value of the given option.
388
        
389
        :param kind: str/bool/int/float. default: str
390
        """
391
        if self.config.has_option('preferences', option):
392
            if kind == 'bool':
393
                return self.config.getboolean('preferences', option)
394
            elif kind == 'int':
395
                return self.config.getint('preferences', option)
396
            elif kind == 'float':
397
                return self.config.getfloat('preferences', option)
398
            else:
399
                return self.config.get('preferences', option)
400
        else:
401
            try:
402
                return self._get_default(option)
403
            except KeyError:
404
                return None
405
    
406
    def set_preference(self, option, value):
407
        """ Set the value of the given option. """
408
        if self.config.has_section('preferences'):
409
            self.config.set('preferences', option, value)
410
        else:
411
            self.config.add_section('preferences')
412
            self.config.set('preferences', option, value)
413
    
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
414
    def get_bookmarks(self):
415
        """ Return the list of bookmarks. """
416
        bookmarks = self.config.sections()
417
        if self.config.has_section('preferences'):
418
            bookmarks.remove('preferences')
419
        return bookmarks
420
421
    def add_bookmark(self, path):
422
        """ Add bookmark. """
423
        try:
424
            self.config.add_section(path)
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
425
        except ConfigParser.DuplicateSectionError:
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
426
            return False
427
        else:
428
            return True
429
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
430
    def remove_bookmark(self, path):
0.8.32 by Szilveszter Farkas (Phanatic)
Implemented OlivePreferences; some wording fixes.
431
        """ Remove bookmark. """
432
        return self.config.remove_section(path)