1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <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.
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.
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
30
from bzrlib.branch import Branch
31
import bzrlib.errors as errors
32
from bzrlib.workingtree import WorkingTree
34
# Olive GTK UI version
35
__version__ = '0.11.0'
38
if sys.platform == 'win32':
39
gladefile = os.path.dirname(sys.executable) + "/share/olive/olive.glade"
41
gladefile = "/usr/share/olive/olive.glade"
43
if not os.path.exists(gladefile):
44
# Load from current directory if not installed
45
gladefile = "olive.glade"
47
if not os.path.exists(gladefile):
49
print _('Glade file cannot be found.')
52
from dialog import error_dialog, info_dialog
55
""" The main Olive GTK frontend class. This is called when launching the
59
self.toplevel = gtk.glade.XML(gladefile, 'window_main', 'olive-gtk')
61
self.window = self.toplevel.get_widget('window_main')
63
self.pref = OlivePreferences()
65
# Initialize the statusbar
66
self.statusbar = self.toplevel.get_widget('statusbar')
67
self.context_id = self.statusbar.get_context_id('olive')
70
self.window_main = self.toplevel.get_widget('window_main')
72
self.hpaned_main = self.toplevel.get_widget('hpaned_main')
74
self.treeview_left = self.toplevel.get_widget('treeview_left')
75
self.treeview_right = self.toplevel.get_widget('treeview_right')
76
# Get some important menu items
77
self.menuitem_add_files = self.toplevel.get_widget('menuitem_add_files')
78
self.menuitem_remove_files = self.toplevel.get_widget('menuitem_remove_file')
79
self.menuitem_file_make_directory = self.toplevel.get_widget('menuitem_file_make_directory')
80
self.menuitem_file_rename = self.toplevel.get_widget('menuitem_file_rename')
81
self.menuitem_file_move = self.toplevel.get_widget('menuitem_file_move')
82
self.menuitem_view_show_hidden_files = self.toplevel.get_widget('menuitem_view_show_hidden_files')
83
self.menuitem_branch = self.toplevel.get_widget('menuitem_branch')
84
self.menuitem_branch_init = self.toplevel.get_widget('menuitem_branch_initialize')
85
self.menuitem_branch_get = self.toplevel.get_widget('menuitem_branch_get')
86
self.menuitem_branch_checkout = self.toplevel.get_widget('menuitem_branch_checkout')
87
self.menuitem_branch_pull = self.toplevel.get_widget('menuitem_branch_pull')
88
self.menuitem_branch_push = self.toplevel.get_widget('menuitem_branch_push')
89
self.menuitem_branch_commit = self.toplevel.get_widget('menuitem_branch_commit')
90
self.menuitem_branch_status = self.toplevel.get_widget('menuitem_branch_status')
91
self.menuitem_branch_missing = self.toplevel.get_widget('menuitem_branch_missing_revisions')
92
self.menuitem_stats = self.toplevel.get_widget('menuitem_stats')
93
self.menuitem_stats_diff = self.toplevel.get_widget('menuitem_stats_diff')
94
self.menuitem_stats_log = self.toplevel.get_widget('menuitem_stats_log')
95
# Get some toolbuttons
96
#self.menutoolbutton_diff = self.toplevel.get_widget('menutoolbutton_diff')
97
self.toolbutton_diff = self.toplevel.get_widget('toolbutton_diff')
98
self.toolbutton_log = self.toplevel.get_widget('toolbutton_log')
99
self.toolbutton_commit = self.toplevel.get_widget('toolbutton_commit')
100
self.toolbutton_pull = self.toplevel.get_widget('toolbutton_pull')
101
self.toolbutton_push = self.toplevel.get_widget('toolbutton_push')
102
# Get the drive selector
103
self.combobox_drive = gtk.combo_box_new_text()
104
self.combobox_drive.connect("changed", self._refresh_drives)
106
self.vbox_main_right = self.toplevel.get_widget('vbox_main_right')
109
# Dictionary for signal_autoconnect
110
dic = { "on_window_main_destroy": gtk.main_quit,
111
"on_window_main_delete_event": self.on_window_main_delete_event,
112
"on_quit_activate": self.on_window_main_delete_event,
113
"on_about_activate": self.on_about_activate,
114
"on_menuitem_add_files_activate": self.on_menuitem_add_files_activate,
115
"on_menuitem_remove_file_activate": self.on_menuitem_remove_file_activate,
116
"on_menuitem_file_make_directory_activate": self.on_menuitem_file_make_directory_activate,
117
"on_menuitem_file_move_activate": self.on_menuitem_file_move_activate,
118
"on_menuitem_file_rename_activate": self.on_menuitem_file_rename_activate,
119
"on_menuitem_view_show_hidden_files_activate": self.on_menuitem_view_show_hidden_files_activate,
120
"on_menuitem_view_refresh_activate": self.on_menuitem_view_refresh_activate,
121
"on_menuitem_branch_initialize_activate": self.on_menuitem_branch_initialize_activate,
122
"on_menuitem_branch_get_activate": self.on_menuitem_branch_get_activate,
123
"on_menuitem_branch_checkout_activate": self.on_menuitem_branch_checkout_activate,
124
"on_menuitem_branch_commit_activate": self.on_menuitem_branch_commit_activate,
125
"on_menuitem_branch_push_activate": self.on_menuitem_branch_push_activate,
126
"on_menuitem_branch_pull_activate": self.on_menuitem_branch_pull_activate,
127
"on_menuitem_branch_status_activate": self.on_menuitem_branch_status_activate,
128
"on_menuitem_branch_missing_revisions_activate": self.on_menuitem_branch_missing_revisions_activate,
129
"on_menuitem_stats_diff_activate": self.on_menuitem_stats_diff_activate,
130
"on_menuitem_stats_log_activate": self.on_menuitem_stats_log_activate,
131
"on_menuitem_stats_infos_activate": self.on_menuitem_stats_infos_activate,
132
"on_toolbutton_refresh_clicked": self.on_menuitem_view_refresh_activate,
133
"on_toolbutton_log_clicked": self.on_menuitem_stats_log_activate,
134
#"on_menutoolbutton_diff_clicked": self.on_menuitem_stats_diff_activate,
135
"on_toolbutton_diff_clicked": self.on_menuitem_stats_diff_activate,
136
"on_toolbutton_commit_clicked": self.on_menuitem_branch_commit_activate,
137
"on_toolbutton_pull_clicked": self.on_menuitem_branch_pull_activate,
138
"on_toolbutton_push_clicked": self.on_menuitem_branch_push_activate,
139
"on_treeview_right_button_press_event": self.on_treeview_right_button_press_event,
140
"on_treeview_right_row_activated": self.on_treeview_right_row_activated,
141
"on_treeview_left_button_press_event": self.on_treeview_left_button_press_event,
142
"on_treeview_left_row_activated": self.on_treeview_left_row_activated }
144
# Connect the signals to the handlers
145
self.toplevel.signal_autoconnect(dic)
147
# Apply window size and position
148
width = self.pref.get_preference('window_width', 'int')
149
height = self.pref.get_preference('window_height', 'int')
150
self.window.resize(width, height)
151
x = self.pref.get_preference('window_x', 'int')
152
y = self.pref.get_preference('window_y', 'int')
153
self.window.move(x, y)
154
# Apply paned position
155
pos = self.pref.get_preference('paned_position', 'int')
156
self.hpaned_main.set_position(pos)
158
# Apply menu to the toolbutton
159
#menubutton = self.toplevel.get_widget('menutoolbutton_diff')
160
#menubutton.set_menu(handler.menu.toolbar_diff)
162
# Now we can show the window
165
# Show drive selector if under Win32
166
if sys.platform == 'win32':
167
self.vbox_main_right.pack_start(self.combobox_drive, False, True, 0)
168
self.vbox_main_right.reorder_child(self.combobox_drive, 0)
169
self.combobox_drive.show()
170
self.gen_hard_selector()
175
self.menuitem_view_show_hidden_files.set_active(self.pref.get_preference('dotted_files', 'bool'))
177
self.set_path(os.getcwd())
180
def set_path(self, path):
182
self.notbranch = False
184
self.wt, self.wtpath = WorkingTree.open_containing(self.path)
185
except errors.NotBranchError:
186
self.notbranch = True
191
def on_about_activate(self, widget):
192
from dialog import about
195
def on_menuitem_add_files_activate(self, widget):
196
""" Add file(s)... menu handler. """
197
from add import OliveAdd
198
add = OliveAdd(self.wt, self.wtpath, self.get_selected_right())
201
def on_menuitem_branch_get_activate(self, widget):
202
""" Branch/Get... menu handler. """
203
from branch import OliveBranch
204
branch = OliveBranch()
207
def on_menuitem_branch_checkout_activate(self, widget):
208
""" Branch/Checkout... menu handler. """
209
from checkout import OliveCheckout
210
checkout = OliveCheckout()
213
def on_menuitem_branch_commit_activate(self, widget):
214
""" Branch/Commit... menu handler. """
215
from commit import OliveCommit
216
commit = OliveCommit(self.wt, self.wtpath)
219
def on_menuitem_branch_missing_revisions_activate(self, widget):
220
""" Branch/Missing revisions menu handler. """
221
local_branch = self.wt.branch
223
other_branch = local_branch.get_parent()
224
if other_branch is None:
225
error_dialog(_('Parent location is unknown'),
226
_('Cannot determine missing revisions if no parent location is known.'))
229
remote_branch = Branch.open(other_branch)
231
if remote_branch.base == local_branch.base:
232
remote_branch = local_branch
234
ret = len(local_branch.missing_revisions(remote_branch))
237
info_dialog(_('There are missing revisions'),
238
_('%d revision(s) missing.') % ret)
240
info_dialog(_('Local branch up to date'),
241
_('There are no missing revisions.'))
243
def on_menuitem_branch_pull_activate(self, widget):
244
""" Branch/Pull menu handler. """
245
branch_to = self.wt.branch
247
location = branch_to.get_parent()
249
error_dialog(_('Parent location is unknown'),
250
_('Pulling is not possible until there is a parent location.'))
254
branch_from = Branch.open(location)
255
except errors.NotBranchError:
256
error_dialog(_('Directory is not a branch'),
257
_('You can perform this action only in a branch.'))
259
if branch_to.get_parent() is None:
260
branch_to.set_parent(branch_from.base)
262
#old_rh = branch_to.revision_history()
263
#if tree_to is not None:
264
# tree_to.pull(branch_from)
266
# branch_to.pull(branch_from)
267
branch_to.pull(branch_from)
269
# TODO: get the number of pulled revisions
272
info_dialog(_('Pull successful'), _('%d revision(s) pulled.') % ret)
274
def on_menuitem_branch_push_activate(self, widget):
275
""" Branch/Push... menu handler. """
276
from push import OlivePush
277
push = OlivePush(self.wt.branch)
280
def on_menuitem_branch_status_activate(self, widget):
281
""" Branch/Status... menu handler. """
282
from status import OliveStatus
283
status = OliveStatus(self.wt, self.wtpath)
286
def on_menuitem_branch_initialize_activate(self, widget):
287
""" Initialize current directory. """
288
import bzrlib.bzrdir as bzrdir
291
if not os.path.exists(self.path):
295
existing_bzrdir = bzrdir.BzrDir.open(self.path)
296
except errors.NotBranchError:
297
bzrdir.BzrDir.create_branch_convenience(self.path)
299
if existing_bzrdir.has_branch():
300
if existing_bzrdir.has_workingtree():
301
raise errors.AlreadyBranchError(self.path)
303
raise errors.BranchExistsWithoutWorkingTree(self.path)
305
existing_bzrdir.create_branch()
306
existing_bzrdir.create_workingtree()
307
except errors.AlreadyBranchError, errmsg:
308
error_dialog(_('Directory is already a branch'),
309
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
310
except errors.BranchExistsWithoutWorkingTree, errmsg:
311
error_dialog(_('Branch without a working tree'),
312
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
314
info_dialog(_('Initialize successful'),
315
_('Directory successfully initialized.'))
318
def on_menuitem_file_make_directory_activate(self, widget):
319
""" File/Make directory... menu handler. """
320
from mkdir import OliveMkdir
321
mkdir = OliveMkdir(self.wt, self.wtpath)
324
def on_menuitem_file_move_activate(self, widget):
325
""" File/Move... menu handler. """
326
from move import OliveMove
327
move = OliveMove(self.wt, self.wtpath, self.get_selected_right())
330
def on_menuitem_file_rename_activate(self, widget):
331
""" File/Rename... menu handler. """
332
from rename import OliveRename
333
rename = OliveRename(self.wt, self.wtpath, self.get_selected_right())
336
def on_menuitem_remove_file_activate(self, widget):
337
""" Remove (unversion) selected file. """
338
from remove import OliveRemove
339
remove = OliveRemove(self.wt, self.wtpath, self.get_selected_right())
342
def on_menuitem_stats_diff_activate(self, widget):
343
""" Statistics/Differences... menu handler. """
344
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
345
window = DiffWindow()
346
parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
347
window.set_diff(self.wt.branch.nick, self.wt, parent_tree)
350
def on_menuitem_stats_infos_activate(self, widget):
351
""" Statistics/Informations... menu handler. """
352
from info import OliveInfo
353
info = OliveInfo(self.wt)
356
def on_menuitem_stats_log_activate(self, widget):
357
""" Statistics/Log... menu handler. """
358
from bzrlib.plugins.gtk.viz.branchwin import BranchWindow
359
window = BranchWindow()
360
window.set_branch(self.wt.branch, self.wt.branch.last_revision(), None)
363
def on_menuitem_view_refresh_activate(self, widget):
364
""" View/Refresh menu handler. """
365
# Refresh the left pane
367
# Refresh the right pane
371
def on_menuitem_view_show_hidden_files_activate(self, widget):
372
""" View/Show hidden files menu handler. """
373
self.pref.set_preference('dotted_files', widget.get_active())
375
def on_treeview_left_button_press_event(self, widget, event):
376
""" Occurs when somebody right-clicks in the bookmark list. """
377
if event.button == 3:
378
# Don't show context with nothing selected
379
if self.get_selected_left() == None:
382
self.menu.left_context_menu().popup(None, None, None, 0,
385
def on_treeview_left_row_activated(self, treeview, path, view_column):
386
""" Occurs when somebody double-clicks or enters an item in the
389
newdir = self.get_selected_left()
393
self.set_path(newdir)
396
def on_treeview_right_button_press_event(self, widget, event):
397
""" Occurs when somebody right-clicks in the file list. """
398
if event.button == 3:
400
from menu import OliveMenu
401
menu = OliveMenu(self.get_path(), self.get_selected_right())
403
m_add = menu.ui.get_widget('/context_right/add')
404
m_remove = menu.ui.get_widget('/context_right/remove')
405
m_commit = menu.ui.get_widget('/context_right/commit')
406
m_diff = menu.ui.get_widget('/context_right/diff')
407
# check if we're in a branch
409
from bzrlib.branch import Branch
410
Branch.open_containing(self.get_path())
411
m_add.set_sensitive(True)
412
m_remove.set_sensitive(True)
413
m_commit.set_sensitive(True)
414
m_diff.set_sensitive(True)
415
except errors.NotBranchError:
416
m_add.set_sensitive(False)
417
m_remove.set_sensitive(False)
418
m_commit.set_sensitive(False)
419
m_diff.set_sensitive(False)
420
menu.right_context_menu().popup(None, None, None, 0,
423
def on_treeview_right_row_activated(self, treeview, path, view_column):
424
""" Occurs when somebody double-clicks or enters an item in the
428
from launch import launch
430
newdir = self.get_selected_right()
433
self.set_path(os.path.split(self.get_path())[0])
435
fullpath = self.get_path() + os.sep + newdir
436
if os.path.isdir(fullpath):
437
# selected item is an existant directory
438
self.set_path(fullpath)
444
def on_window_main_delete_event(self, widget, event=None):
445
""" Do some stuff before exiting. """
446
width, height = self.window_main.get_size()
447
self.pref.set_preference('window_width', width)
448
self.pref.set_preference('window_height', height)
449
x, y = self.window_main.get_position()
450
self.pref.set_preference('window_x', x)
451
self.pref.set_preference('window_y', y)
452
self.pref.set_preference('paned_position',
453
self.hpaned_main.get_position())
456
self.window_main.destroy()
458
def _load_left(self):
459
""" Load data into the left panel. (Bookmarks) """
461
treestore = gtk.TreeStore(str, str)
464
bookmarks = self.pref.get_bookmarks()
466
# Add them to the TreeStore
467
titer = treestore.append(None, [_('Bookmarks'), None])
468
for item in bookmarks:
469
title = self.pref.get_bookmark_title(item)
470
treestore.append(titer, [title, item])
472
# Create the column and add it to the TreeView
473
self.treeview_left.set_model(treestore)
474
tvcolumn_bookmark = gtk.TreeViewColumn(_('Bookmark'))
475
self.treeview_left.append_column(tvcolumn_bookmark)
478
cell = gtk.CellRendererText()
479
tvcolumn_bookmark.pack_start(cell, True)
480
tvcolumn_bookmark.add_attribute(cell, 'text', 0)
483
self.treeview_left.expand_all()
485
def _load_right(self):
486
""" Load data into the right panel. (Filelist) """
488
liststore = gtk.ListStore(str, str, str)
493
# Fill the appropriate lists
494
dotted_files = self.pref.get_preference('dotted_files', 'bool')
495
for item in os.listdir(self.path):
496
if not dotted_files and item[0] == '.':
498
if os.path.isdir(self.path + os.sep + item):
507
if not self.notbranch:
508
branch = self.wt.branch
509
tree2 = self.wt.branch.repository.revision_tree(branch.last_revision())
511
delta = self.wt.changes_from(tree2, want_unchanged=True)
513
# Add'em to the ListStore
515
liststore.append([gtk.STOCK_DIRECTORY, item, ''])
518
if not self.notbranch:
519
filename = self.wt.relpath(self.path + os.sep + item)
521
for rpath, id, kind, text_modified, meta_modified in delta.renamed:
522
if rpath == filename:
524
for rpath, id, kind in delta.added:
525
if rpath == filename:
527
for rpath, id, kind in delta.removed:
528
if rpath == filename:
530
for rpath, id, kind, text_modified, meta_modified in delta.modified:
531
if rpath == filename:
533
for rpath, id, kind in delta.unchanged:
534
if rpath == filename:
538
# status = fileops.status(path + os.sep + item)
539
#except errors.PermissionDenied:
542
if status == 'renamed':
544
elif status == 'removed':
546
elif status == 'added':
548
elif status == 'modified':
550
elif status == 'unchanged':
554
liststore.append([gtk.STOCK_FILE, item, st])
556
# Create the columns and add them to the TreeView
557
self.treeview_right.set_model(liststore)
558
tvcolumn_filename = gtk.TreeViewColumn(_('Filename'))
559
tvcolumn_status = gtk.TreeViewColumn(_('Status'))
560
self.treeview_right.append_column(tvcolumn_filename)
561
self.treeview_right.append_column(tvcolumn_status)
564
cellpb = gtk.CellRendererPixbuf()
565
cell = gtk.CellRendererText()
566
tvcolumn_filename.pack_start(cellpb, False)
567
tvcolumn_filename.pack_start(cell, True)
568
tvcolumn_filename.set_attributes(cellpb, stock_id=0)
569
tvcolumn_filename.add_attribute(cell, 'text', 1)
570
tvcolumn_status.pack_start(cell, True)
571
tvcolumn_status.add_attribute(cell, 'text', 2)
573
self.menuitem_branch_init.set_sensitive(self.notbranch)
574
# Check if current directory is a branch
575
self.menuitem_branch_get.set_sensitive(not self.notbranch)
576
self.menuitem_branch_checkout.set_sensitive(not self.notbranch)
577
self.menuitem_branch_pull.set_sensitive(not self.notbranch)
578
self.menuitem_branch_push.set_sensitive(not self.notbranch)
579
self.menuitem_branch_commit.set_sensitive(not self.notbranch)
580
self.menuitem_branch_status.set_sensitive(not self.notbranch)
581
self.menuitem_branch_missing.set_sensitive(not self.notbranch)
582
self.menuitem_stats.set_sensitive(not self.notbranch)
583
self.menuitem_add_files.set_sensitive(not self.notbranch)
584
self.menuitem_remove_files.set_sensitive(not self.notbranch)
585
self.menuitem_file_make_directory.set_sensitive(not self.notbranch)
586
self.menuitem_file_rename.set_sensitive(not self.notbranch)
587
self.menuitem_file_move.set_sensitive(not self.notbranch)
588
#self.menutoolbutton_diff.set_sensitive(True)
589
self.toolbutton_diff.set_sensitive(not self.notbranch)
590
self.toolbutton_log.set_sensitive(not self.notbranch)
591
self.toolbutton_commit.set_sensitive(not self.notbranch)
592
self.toolbutton_pull.set_sensitive(not self.notbranch)
593
self.toolbutton_push.set_sensitive(not self.notbranch)
595
def get_selected_right(self):
596
""" Get the selected filename. """
597
treeselection = self.treeview_right.get_selection()
598
(model, iter) = treeselection.get_selected()
603
return model.get_value(iter, 1)
605
def get_selected_left(self):
606
""" Get the selected bookmark. """
607
treeselection = self.treeview_left.get_selection()
608
(model, iter) = treeselection.get_selected()
613
return model.get_value(iter, 1)
615
def set_statusbar(self, message):
616
""" Set the statusbar message. """
617
self.statusbar.push(self.context_id, message)
619
def clear_statusbar(self):
620
""" Clean the last message from the statusbar. """
621
self.statusbar.pop(self.context_id)
623
def refresh_left(self):
624
""" Refresh the bookmark list. """
626
# Get TreeStore and clear it
627
treestore = self.treeview_left.get_model()
631
bookmarks = self.pref.get_bookmarks()
633
# Add them to the TreeStore
634
titer = treestore.append(None, [_('Bookmarks'), None])
635
for item in bookmarks:
636
title = self.pref.get_bookmark_title(item)
637
treestore.append(titer, [title, item])
639
# Add the TreeStore to the TreeView
640
self.treeview_left.set_model(treestore)
643
self.treeview_left.expand_all()
645
def refresh_right(self, path=None):
646
""" Refresh the file list. """
647
from bzrlib.workingtree import WorkingTree
650
path = self.get_path()
652
# A workaround for double-clicking Bookmarks
653
if not os.path.exists(path):
656
# Get ListStore and clear it
657
liststore = self.treeview_right.get_model()
663
# Fill the appropriate lists
664
dotted_files = self.pref.get_preference('dotted_files', 'bool')
665
for item in os.listdir(path):
666
if not dotted_files and item[0] == '.':
668
if os.path.isdir(path + os.sep + item):
677
# Try to open the working tree
680
tree1 = WorkingTree.open_containing(path)[0]
681
except errors.NotBranchError:
683
except errors.PermissionDenied:
684
print "DEBUG: permission denied."
687
branch = tree1.branch
688
tree2 = tree1.branch.repository.revision_tree(branch.last_revision())
690
delta = tree1.changes_from(tree2, want_unchanged=True)
692
# Add'em to the ListStore
694
liststore.append([gtk.STOCK_DIRECTORY, item, ''])
698
filename = tree1.relpath(path + os.sep + item)
700
for rpath, id, kind, text_modified, meta_modified in delta.renamed:
701
if rpath == filename:
703
for rpath, id, kind in delta.added:
704
if rpath == filename:
706
for rpath, id, kind, text_modified, meta_modified in delta.removed:
707
if rpath == filename:
709
for rpath, id, kind, text_modified, meta_modified in delta.modified:
710
if rpath == filename:
712
for rpath, id, kind in delta.unchanged:
713
if rpath == filename:
717
# status = fileops.status(path + os.sep + item)
718
#except errors.PermissionDenied:
721
if status == 'renamed':
723
elif status == 'removed':
725
elif status == 'added':
727
elif status == 'modified':
729
elif status == 'unchanged':
733
liststore.append([gtk.STOCK_FILE, item, st])
735
# Add the ListStore to the TreeView
736
self.treeview_right.set_model(liststore)
738
def _harddisks(self):
739
""" Returns hard drive letters under Win32. """
744
if sys.platform == 'win32':
745
print "pyWin32 modules needed to run Olive on Win32."
751
for drive in string.ascii_uppercase:
752
if win32file.GetDriveType(drive+':') == win32file.DRIVE_FIXED:
753
driveletters.append(drive+':')
756
def gen_hard_selector(self):
757
""" Generate the hard drive selector under Win32. """
758
drives = self._harddisks()
760
self.combobox_drive.append_text(drive)
762
def _refresh_drives(self, combobox):
763
model = combobox.get_model()
764
active = combobox.get_active()
766
drive = model[active][0]
767
self.refresh_right(drive + '\\')
771
class OlivePreferences:
772
""" A class which handles Olive's preferences. """
774
""" Initialize the Preferences class. """
775
# Some default options
776
self.defaults = { 'strict_commit' : False,
777
'dotted_files' : False,
778
'window_width' : 700,
779
'window_height' : 400,
782
'paned_position': 200 }
784
# Create a config parser object
785
self.config = ConfigParser.RawConfigParser()
787
# Load the configuration
788
if sys.platform == 'win32':
789
# Windows - no dotted files
790
self.config.read([os.path.expanduser('~/olive.conf')])
792
self.config.read([os.path.expanduser('~/.olive.conf')])
796
def _get_default(self, option):
797
""" Get the default option for a preference. """
799
ret = self.defaults[option]
806
""" Refresh the configuration. """
807
# First write out the changes
809
# Then load the configuration again
810
if sys.platform == 'win32':
811
# Windows - no dotted files
812
self.config.read([os.path.expanduser('~/olive.conf')])
814
self.config.read([os.path.expanduser('~/.olive.conf')])
817
""" Write the configuration to the appropriate files. """
818
if sys.platform == 'win32':
819
# Windows - no dotted files
820
fp = open(os.path.expanduser('~/olive.conf'), 'w')
821
self.config.write(fp)
824
fp = open(os.path.expanduser('~/.olive.conf'), 'w')
825
self.config.write(fp)
828
def get_bookmarks(self):
829
""" Return the list of bookmarks. """
830
bookmarks = self.config.sections()
831
if self.config.has_section('preferences'):
832
bookmarks.remove('preferences')
835
def add_bookmark(self, path):
836
""" Add bookmark. """
838
self.config.add_section(path)
839
except ConfigParser.DuplicateSectionError:
844
def get_bookmark_title(self, path):
845
""" Get bookmark title. """
847
ret = self.config.get(path, 'title')
848
except ConfigParser.NoOptionError:
853
def set_bookmark_title(self, path, title):
854
""" Set bookmark title. """
855
self.config.set(path, 'title', title)
857
def remove_bookmark(self, path):
858
""" Remove bookmark. """
859
return self.config.remove_section(path)
861
def set_preference(self, option, value):
862
""" Set the value of the given option. """
863
if self.config.has_section('preferences'):
864
self.config.set('preferences', option, value)
866
self.config.add_section('preferences')
867
self.config.set('preferences', option, value)
869
def get_preference(self, option, kind='str'):
870
""" Get the value of the given option.
872
:param kind: str/bool/int/float. default: str
874
if self.config.has_option('preferences', option):
876
#return self.config.getboolean('preferences', option)
879
return self.config.getint('preferences', option)
880
elif kind == 'float':
881
return self.config.getfloat('preferences', option)
883
return self.config.get('preferences', option)
886
return self._get_default(option)