Add manifest to manifest
[gpytage.git] / rename.py
blobb66dde1677d81a0ae4746ea5b03d869aa648639f
1 #!/usr/bin/env python
3 # GPytage rename.py module
5 ############################################################################
6 # Copyright (C) 2008 by Kenneth Prugh, Brian Dolbec #
7 # ken69267@gmail.com #
8 # #
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. #
12 # #
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. #
17 # #
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")
25 import gtk
26 import datastore
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)
42 cb.set_model(model)
43 cell = gtk.CellRendererText()
44 cb.pack_start(cell)
45 cb.add_attribute(cell, 'text', 0)
47 dirs,files = folder_scan()
49 subfiles = []
51 for i in dirs:
52 data = folder_walk(i)
53 for i in data:
54 subfiles.append(i)
56 for i in subfiles:
57 cb.append_text(i)
58 cb.set_active(0)
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)
68 if subfiles == []:
69 sbar = wTree.get_widget("sbar")
70 smsg = sbar.get_context_id("standard message")
71 sbar.pop(smsg)
72 sbar.push(smsg, "Error: No subfiles detected")
73 sbar.show()
75 rDialog.show_all()
76 rDialog.run()
78 def close_renameD(self, arg, rDialog):
79 rDialog.hide()
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()
89 if status == -8:
90 uD.hide()
91 elif status == 1:
92 SaveFile().save()
93 uD.hide()
94 else:
95 uD.hide()
96 return
97 if len(newName):
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]
102 return True
103 datastore.datastore.foreach(findMatch, [oldName, newName])
104 if self.data:
105 model = self.data[0]
106 path = self.data[1]
107 iter = self.data[2]
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)
117 else:
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?
122 rDialog.hide()