5 from PyQt4
import QtCore, QtGui
6 from immutable_loader_info_handler
import ImmutableLoaderInfoHandler
7 from loader_info_handler
import LoaderInfoHandler
8 from ost.gui import LoaderManager
14 MUTABLE_LOADERS_PATH =
"user_loaders.xml"
17 QtCore.QAbstractListModel.__init__(self, parent, *args)
22 self.
immutable_infoh_ = ImmutableLoaderInfoHandler(LoaderListModel.IMMUTABLE_LOADERS_PATH)
23 self.
infoh_ = LoaderInfoHandler(LoaderListModel.MUTABLE_LOADERS_PATH)
28 def AddItem(self, name, loader, row, editable, save):
31 self.
data_[row] = [name, loader, editable]
32 model_index = self.createIndex(row,0)
33 index = self.index(row)
34 end_index = self.createIndex(self.
rowCount(),0)
37 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, end_index)
38 gui.FileLoader.GetLoaderManager().AddRemoteSiteLoader(name, loader)
39 if(loader.IsDefault()):
40 gui.FileLoader.GetLoaderManager().SetDefaultRemoteSiteIdent(name)
45 return self.
data_[row][2]
49 name = self.
data_[row][0]
51 model_index = self.createIndex(row,0)
52 self.infoh_.RemoveLoader(name)
53 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, model_index)
54 self.loader_manager_.RemoveRemoteSiteLoader(name)
59 self.infoh_.StoreLoader(name, loader)
62 self.infoh_.RemoveLoader(name)
65 row = model_index.row()
66 name = self.
data_[row][0]
67 self.
data_[row][1] = loader
68 model_index = self.createIndex(row,0)
69 index = self.index(row)
70 end_index = self.createIndex(self.
rowCount(),0)
73 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, end_index)
74 self.loader_manager_.RemoveRemoteSiteLoader(name)
75 self.loader_manager_.AddRemoteSiteLoader(name, loader)
80 loaders = self.immutable_infoh_.GetLoaders()
81 for k, v
in loaders.iteritems():
84 loaders = self.infoh_.GetLoaders()
85 for k, v
in loaders.iteritems():
89 if model_index.isValid():
90 return self.
data_[model_index.row()][1]
99 for values
in self.
data_:
100 if string == values[0]:
106 return len(self.
data_)
109 if index.isValid()
and index.row()< self.
rowCount():
110 data = self.
data_[index.row()]
111 if role == QtCore.Qt.DisplayRole:
112 return QtCore.QVariant(data[0])
113 return QtCore.QVariant()
118 if not self.
data_[row]:
119 self.
data_[row] = list()
120 if role == QtCore.Qt.EditRole
and self.
NameIsValid(value.toString()):
121 old_name = str(self.
data_[row][0])
122 new_name = value.toString()
123 self.
data_[row][0] = new_name
124 self.infoh_.RenameLoader(old_name,str(new_name))
125 self.emit(QtCore.SIGNAL(
"dataChanged"),index, index)
126 self.loader_manager_.RemoveRemoteSiteLoader(old_name)
127 self.loader_manager_.AddRemoteSiteLoader(str(new_name), self.
data_[row][1])
129 elif role == QtCore.Qt.DisplayRole:
130 self.
data_[row][0] = value.toString()
135 flags = QtCore.QAbstractItemModel.flags(self,index)
137 return flags | QtCore.Qt.ItemIsEditable
140 return QtCore.Qt.ItemIsEnabled
143 self.beginInsertRows(index, position, position)
144 self.data_.insert(position,list())
149 self.beginRemoveRows(index, position, position)
150 del self.
data_[position]