3 # GPytage rename.py module
5 ############################################################################
6 # Copyright (C) 2008 by Kenneth Prugh, Brian Dolbec #
9 # This program is free software; you can redistribute it and#or modify #
10 # it under the terms of the GNU General Public License as published by #
11 # the Free Software Foundation under version 2 of the license. #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program; if not, write to the #
20 # Free Software Foundation, Inc., #
21 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
22 ############################################################################
24 import pygtk
; pygtk
.require("2.0")
27 from helper
import folder_scan
, folder_walk
28 from config
import get_config_path
, config_files
29 from save
import SaveFile
30 from window
import title
, unsavedDialog
, window
32 class rename
: #this is mostly just a test... this may be removed entirely
33 #Ideally we should be able to rename a file with rightclick/current selected
34 def renameDialog(self
, window
):
35 gladefile
= "glade/renamefile.glade"
36 wTree
= gtk
.glade
.XML(gladefile
)
37 rDialog
= wTree
.get_widget("renamed")
39 cb
= wTree
.get_widget("ncb")
41 model
= gtk
.ListStore(str)
43 cell
= gtk
.CellRendererText()
45 cb
.add_attribute(cell
, 'text', 0)
47 dirs
,files
= folder_scan()
60 ftext
= wTree
.get_widget("aentry")
62 addb
= wTree
.get_widget("renameb")
63 closeb
= wTree
.get_widget("closeb")
65 addb
.connect("clicked", self
.renameFile
, cb
, ftext
, rDialog
, window
)
66 closeb
.connect("clicked", self
.close_renameD
, rDialog
)
69 sbar
= wTree
.get_widget("sbar")
70 smsg
= sbar
.get_context_id("standard message")
72 sbar
.push(smsg
, "Error: No subfiles detected")
78 def close_renameD(self
, arg
, rDialog
):
81 def renameFile(self
, arg
, cb
, ftext
, rDialog
, window
):
82 model
= cb
.get_model()
83 index
= cb
.get_active()
84 if index
>= 0: # prevent index errors
85 oldName
= model
[index
][0]
86 newName
= ftext
.get_text()
87 if window
.get_title() != "GPytage":
88 status
, uD
= unsavedDialog()
98 #inline function to get our values
99 def findMatch(model
, path
, iter, user_data
):
100 if model
.get_value(iter, 0).strip('*') == user_data
[0]:
101 self
.data
= [model
, path
, iter]
103 datastore
.datastore
.foreach(findMatch
, [oldName
, newName
])
108 from shutil
import move
109 from config
import get_config_path
110 from helper
import reload
111 pconfig
= get_config_path() # /
112 if model
.get_value(iter, 0) == model
.get_value(iter, 3):
113 #technically this wont ever execute the way I have it now
114 print "RENAME: FILE MATCH"
115 filePath
= pconfig
+model
.get_value(iter, 0)
116 move(filePath
, pconfig
+newName
)
118 print "RENAME: FILE NOMATCH"
119 filePath
= pconfig
+model
.get_value(iter, 3)+'/'+model
.get_value(iter, 0)
120 move(filePath
, pconfig
+model
.get_value(iter, 3)+'/'+newName
)
121 reload() #will nuke unsaved changes, implement a unsaved changes dialog?