store a FileObj as the hidden property on column 0

this is the last version that has priority on the xattr
the next version will have priority on the comments stored in the database
and only set the xattr field as an option
This commit is contained in:
2015-12-20 08:44:42 -05:00
parent c5c30b6433
commit 16b3ee02c5
+25 -7
View File
@@ -112,6 +112,7 @@ def parse():
return parser.parse_args()
#~ class FileObj(QtCore.QObject):
class FileObj():
FILE_IS_DIR = -1
FILE_IS_LINK = -2
@@ -143,8 +144,11 @@ class FileObj():
# we need to move these cases out to a handler
except Exception as e:
print("problem setting the comment on file %s" % (self.fileName,))
print("error "+e)
if os.access(self.fileName, os.W_OK)!=True:
print("error "+repr(e))
## todo: elif file.is_sym() the kernel won't allow comments on symlinks....stored in database
if self.size == FileObj.FILE_IS_LINK:
print("Linux does not allow comments on symlinks; comment is stored in database")
elif os.access(self.fileName, os.W_OK)!=True:
print("you don't appear to have write permissions on this file")
# change the listbox background to yellow
self.displayBox.notifyUnchanged()
@@ -195,12 +199,13 @@ class DirNotes(QMainWindow):
self.curPath, filename = os.path.split(argFilename)
print("working on <"+self.curPath+"> and <"+filename+">")
self.refill()
lb.setHorizontalHeaderItem(0,QTableWidgetItem("File"))
lb.setHorizontalHeaderItem(1,QTableWidgetItem("Date/Time"))
lb.setHorizontalHeaderItem(2,QTableWidgetItem("Size"))
lb.setHorizontalHeaderItem(3,QTableWidgetItem("Comment"))
lb.setSortingEnabled(True)
self.refill()
lb.resizeColumnsToContents()
e = QLabel("View and edit file comments stored in extended attributes user.xdg.comment",win)
@@ -285,10 +290,12 @@ class DirNotes(QMainWindow):
# this is a list of all the file
for i in range(len(d)):
this_file = FileObj(current+'/'+d[i])
print("insert order check: " + d[i] + " " + str(i))
#~ self.files.update({this_file.getName(),this_file})
self.files = self.files + [this_file]
item = QTableWidgetItem(d[i])
item.setFlags(QtCore.Qt.ItemIsEnabled)
item.setData(32,this_file) # keep a hidden copy of the full path
self.lb.setItem(i,0,item)
#lb.itemAt(i,0).setFlags(Qt.ItemIsEnabled) #NoItemFlags)
comment = this_file.getComment()
@@ -315,13 +322,17 @@ class DirNotes(QMainWindow):
def change(self,x):
print("debugging " + x.text() + " r:" + str(x.row()) + " c:" + str(x.column()))
the_file = dn.files[x.row()]
r = the_file.setComment(str(x.text()))
print(" selected file: "+self.lb.item(x.row(),0).data(32).toPyObject().getName())
the_file = self.lb.item(x.row(),0).data(32).toPyObject()
print(" and the row file is "+the_file.getName())
r = the_file.setComment(str(x.text())) ## fix me store the FileObj in the data
if r:
self.db.log(the_file.getName(),x.text())
def restore_from_database(self):
print("restore from database")
fileName = str(self.lb.item(self.lb.currentRow(),0).text())
# retrieve the full path name
fileName = str(self.lb.item(self.lb.currentRow(),0).data(32).toPyObject().getName())
print("using filename: "+fileName)
existing_comment = str(self.lb.item(self.lb.currentRow(),3).text())
print("restore....existing="+existing_comment+"=")
if len(existing_comment) > 0:
@@ -402,3 +413,10 @@ user.xdg.publisher
-choose & cancel buttons
'''
''' commandline xattr
getfattr -h (don't follow symlink) -d (dump all properties)
'''
''' qt set color
newitem.setData(Qt.BackgroundRole,QBrush(QColor("yellow")))
'''