def make_bookmark(self, spath): if self.written: return if not os.path.exists(self.config_path): #do not write shortcuts if file was not created by Qt5 himself return url = pathlib.Path(spath).as_uri() settings_qt5 = QSettings(self.config_path, QSettings.IniFormat) if not settings_qt5.isWritable(): return shortcuts = ray.get_list_in_settings(settings_qt5, 'FileDialog/shortcuts') for sc in shortcuts: sc_url = QUrl(sc) if sc_url.isLocalFile() and sc_url.toLocalFile() == spath: return shortcuts.append(url) settings_qt5.setValue('FileDialog/shortcuts', shortcuts) settings_qt5.sync() self.written = True
def __init__(self,dbfile,port): self._con=connect(dbfile) from PyQt5.QtCore import QSettings from os import sep from os.path import dirname, join, exists setting = QSettings(QSettings.IniFormat, QSettings.UserScope, 'KonkukUniv', 'rebauth') setting.isWritable() #it makes setting folder if doesn't exist self._settingPath = dirname(setting.fileName().replace('/',sep)) self._cursor = connect(join(self._settingPath,dbfile)) self._cursor.row_factory = Row self._cursor=self._cursor.cursor() dbInitialQueries=(('Cert', 'PIN int default 0', 'ipaddr text not null', 'port int not null','key blob not null','cnt blob not null') ,('Tactics', 'ID int NOT NULL', 'exec_order int default 0', 'type int NOT NULL', 'script text') ,('Strategy', 'URL text NOT NULL', 'type integer NOT NULL','hash blob', 'valid int default 0')) for q in dbInitialQueries: self.executeQuery('CREATE TABLE IF NOT EXISTS '+q[0]+'('+','.join(q[1:])+')') self._cursor.connection.commit() self.socketPool = ClientSocketPool(port, self)
def updateLocationsTable(self): self.locationsTable.setUpdatesEnabled(False) self.locationsTable.setRowCount(0) for i in range(2): if i == 0: if self.scope() == QSettings.SystemScope: continue actualScope = QSettings.UserScope else: actualScope = QSettings.SystemScope for j in range(2): if j == 0: if not self.application(): continue actualApplication = self.application() else: actualApplication = "" settings = QSettings( self.format(), actualScope, self.organization(), actualApplication ) row = self.locationsTable.rowCount() self.locationsTable.setRowCount(row + 1) item0 = QTableWidgetItem() item0.setText(settings.fileName()) item1 = QTableWidgetItem() disable = not (settings.childKeys() or settings.childGroups()) if row == 0: if settings.isWritable(): item1.setText("Read-write") disable = False else: item1.setText("Read-only") self.buttonBox.button(QDialogButtonBox.Ok).setDisabled(disable) else: item1.setText("Read-only fallback") if disable: item0.setFlags(item0.flags() & ~Qt.ItemIsEnabled) item1.setFlags(item1.flags() & ~Qt.ItemIsEnabled) self.locationsTable.setItem(row, 0, item0) self.locationsTable.setItem(row, 1, item1) self.locationsTable.setUpdatesEnabled(True)
def updateLocationsTable(self): self.locationsTable.setUpdatesEnabled(False) self.locationsTable.setRowCount(0) for i in range(2): if i == 0: if self.scope() == QSettings.SystemScope: continue actualScope = QSettings.UserScope else: actualScope = QSettings.SystemScope for j in range(2): if j == 0: if not self.application(): continue actualApplication = self.application() else: actualApplication = '' settings = QSettings(self.format(), actualScope, self.organization(), actualApplication) row = self.locationsTable.rowCount() self.locationsTable.setRowCount(row + 1) item0 = QTableWidgetItem() item0.setText(settings.fileName()) item1 = QTableWidgetItem() disable = not (settings.childKeys() or settings.childGroups()) if row == 0: if settings.isWritable(): item1.setText("Read-write") disable = False else: item1.setText("Read-only") self.buttonBox.button(QDialogButtonBox.Ok).setDisabled(disable) else: item1.setText("Read-only fallback") if disable: item0.setFlags(item0.flags() & ~Qt.ItemIsEnabled) item1.setFlags(item1.flags() & ~Qt.ItemIsEnabled) self.locationsTable.setItem(row, 0, item0) self.locationsTable.setItem(row, 1, item1) self.locationsTable.setUpdatesEnabled(True)
def remove_bookmark(self, spath): if not self.written: return if not os.path.exists(self.config_path): self.written = False return url = pathlib.Path(spath).as_uri() settings_qt4 = QSettings(self.config_path, QSettings.IniFormat) if not settings_qt4.isWritable(): self.written = False return data = settings_qt4.value('Qt/filedialog') stream = QDataStream(data, QIODevice.ReadOnly) magic = stream.readUInt32() version = stream.readUInt32() if not (magic == QFileDialogMagic and version == 3): self.written = False return split_states = stream.readBytes() bookmark_found = False bookmarks_len = stream.readUInt32() bookmarks = [] for bm in range(bookmarks_len): qUrl = QUrl() stream >> qUrl if qUrl.isLocalFile() and qUrl.toLocalFile() == spath: bookmark_found = True else: bookmarks.append(qUrl) if not bookmark_found: self.written = False return history_len = stream.readUInt32() history = [] for h in range(history_len): his = stream.readQString() history.append(his) current_dir = stream.readQString() header_data = stream.readBytes() view_mode = stream.readUInt32() #now rewrite bytes new_data = QByteArray() new_stream = QDataStream(new_data, QIODevice.WriteOnly) new_stream.writeUInt32(magic) new_stream.writeUInt32(3) new_stream.writeBytes(split_states) new_stream.writeUInt32(bookmarks_len-1) for bm in bookmarks: new_stream << bm qUrl = QUrl(url) new_stream << qUrl new_stream.writeQStringList(history) new_stream.writeQString(current_dir) new_stream.writeBytes(header_data) new_stream.writeUInt32(view_mode) settings_qt4.setValue('Qt/filedialog', new_data) settings_qt4.sync() self.written = False