mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add ability to specify frequently used directories on linux
This commit is contained in:
parent
8a111f5730
commit
27bcf6071e
@ -15,7 +15,7 @@
|
|||||||
""" The GUI for libprs500. """
|
""" The GUI for libprs500. """
|
||||||
import sys, os, re, StringIO, traceback
|
import sys, os, re, StringIO, traceback
|
||||||
from PyQt4.QtCore import QVariant, QSettings, QFileInfo, QObject, SIGNAL, QBuffer, \
|
from PyQt4.QtCore import QVariant, QSettings, QFileInfo, QObject, SIGNAL, QBuffer, \
|
||||||
QByteArray, QLocale, QTranslator
|
QByteArray, QLocale, QTranslator, QUrl
|
||||||
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
||||||
QIcon, QTableView
|
QIcon, QTableView
|
||||||
|
|
||||||
@ -174,6 +174,13 @@ def file_icon_provider():
|
|||||||
global _file_icon_provider
|
global _file_icon_provider
|
||||||
return _file_icon_provider
|
return _file_icon_provider
|
||||||
|
|
||||||
|
_sidebar_directories = []
|
||||||
|
def set_sidebar_directories(dirs):
|
||||||
|
global _sidebar_directories
|
||||||
|
if dirs is None:
|
||||||
|
dirs = QSettings().value('frequently used directories', QVariant([])).toStringList()
|
||||||
|
_sidebar_directories = [QUrl.fromLocalFile(i) for i in dirs]
|
||||||
|
|
||||||
class FileDialog(QObject):
|
class FileDialog(QObject):
|
||||||
def __init__(self, title='Choose Files',
|
def __init__(self, title='Choose Files',
|
||||||
filters=[],
|
filters=[],
|
||||||
@ -208,6 +215,8 @@ class FileDialog(QObject):
|
|||||||
state = settings.value(name, QVariant()).toByteArray()
|
state = settings.value(name, QVariant()).toByteArray()
|
||||||
if not self.fd.restoreState(state):
|
if not self.fd.restoreState(state):
|
||||||
self.fd.setDirectory(os.path.expanduser('~'))
|
self.fd.setDirectory(os.path.expanduser('~'))
|
||||||
|
osu = [i for i in self.fd.sidebarUrls()]
|
||||||
|
self.fd.setSidebarUrls(osu + _sidebar_directories)
|
||||||
QObject.connect(self.fd, SIGNAL('accepted()'), self.save_dir)
|
QObject.connect(self.fd, SIGNAL('accepted()'), self.save_dir)
|
||||||
self.accepted = self.fd.exec_() == QFileDialog.Accepted
|
self.accepted = self.fd.exec_() == QFileDialog.Accepted
|
||||||
else:
|
else:
|
||||||
|
@ -12,14 +12,14 @@
|
|||||||
## You should have received a copy of the GNU General Public License along
|
## You should have received a copy of the GNU General Public License along
|
||||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
from libprs500.gui2 import error_dialog
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from PyQt4.QtGui import QDialog
|
from PyQt4.QtGui import QDialog
|
||||||
from PyQt4.QtCore import QSettings, QVariant, SIGNAL
|
from PyQt4.QtCore import QSettings, QVariant, SIGNAL, QStringList
|
||||||
|
|
||||||
|
from libprs500 import islinux
|
||||||
from libprs500.gui2.dialogs.config_ui import Ui_Dialog
|
from libprs500.gui2.dialogs.config_ui import Ui_Dialog
|
||||||
from libprs500.gui2 import qstring_to_unicode, choose_dir
|
from libprs500.gui2 import qstring_to_unicode, choose_dir, error_dialog
|
||||||
|
|
||||||
class ConfigDialog(QDialog, Ui_Dialog):
|
class ConfigDialog(QDialog, Ui_Dialog):
|
||||||
|
|
||||||
@ -36,9 +36,27 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.location.setText(os.path.dirname(path))
|
self.location.setText(os.path.dirname(path))
|
||||||
self.connect(self.browse_button, SIGNAL('clicked(bool)'), self.browse)
|
self.connect(self.browse_button, SIGNAL('clicked(bool)'), self.browse)
|
||||||
|
|
||||||
|
dirs = settings.value('frequently used directories', QVariant(QStringList())).toStringList()
|
||||||
|
self.directory_list.addItems(dirs)
|
||||||
|
self.connect(self.add_button, SIGNAL('clicked(bool)'), self.add_dir)
|
||||||
|
self.connect(self.remove_button, SIGNAL('clicked(bool)'), self.remove_dir)
|
||||||
|
if not islinux:
|
||||||
|
self.dirs_box.setVisible(False)
|
||||||
|
|
||||||
def browse(self):
|
def browse(self):
|
||||||
dir = choose_dir(self, 'database location dialog', 'Select database location')
|
dir = choose_dir(self, 'database location dialog', 'Select database location')
|
||||||
self.location.setText(dir)
|
if dir:
|
||||||
|
self.location.setText(dir)
|
||||||
|
|
||||||
|
def add_dir(self):
|
||||||
|
dir = choose_dir(self, 'Add freq dir dialog', 'select directory')
|
||||||
|
if dir:
|
||||||
|
self.directory_list.addItem(dir)
|
||||||
|
|
||||||
|
def remove_dir(self):
|
||||||
|
idx = self.directory_list.currentRow()
|
||||||
|
if idx >= 0:
|
||||||
|
self.directory_list.takeItem(idx)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
path = qstring_to_unicode(self.location.text())
|
path = qstring_to_unicode(self.location.text())
|
||||||
@ -50,4 +68,6 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
d.exec_()
|
d.exec_()
|
||||||
else:
|
else:
|
||||||
self.database_location = os.path.abspath(path)
|
self.database_location = os.path.abspath(path)
|
||||||
|
self.directories = [qstring_to_unicode(self.directory_list.item(i).text()) for i in range(self.directory_list.count())]
|
||||||
|
QSettings().setValue('frequently used directories', QVariant(self.directories))
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>408</width>
|
||||||
<height>300</height>
|
<height>412</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
@ -39,6 +39,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="browse_button" >
|
<widget class="QToolButton" name="browse_button" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Browse for the new database location</string>
|
||||||
|
</property>
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
@ -52,6 +55,101 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" >
|
<item row="1" column="0" >
|
||||||
|
<widget class="QGroupBox" name="dirs_box" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>Frequently used directories</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<layout class="QHBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="directory_list" >
|
||||||
|
<property name="alternatingRowColors" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize" >
|
||||||
|
<size>
|
||||||
|
<width>22</width>
|
||||||
|
<height>22</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" >
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" >
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="add_button" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Add a directory to the frequently used directories list</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >:/images/plus.svg</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" >
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="remove_button" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Remove a directory from the frequently used directories list</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >:/images/list_remove.svg</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" >
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" >
|
||||||
<spacer>
|
<spacer>
|
||||||
<property name="orientation" >
|
<property name="orientation" >
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -92,8 +190,8 @@
|
|||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel" >
|
||||||
<x>248</x>
|
<x>227</x>
|
||||||
<y>254</y>
|
<y>279</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel" >
|
<hint type="destinationlabel" >
|
||||||
<x>157</x>
|
<x>157</x>
|
||||||
@ -108,8 +206,8 @@
|
|||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel" >
|
||||||
<x>316</x>
|
<x>295</x>
|
||||||
<y>260</y>
|
<y>285</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel" >
|
<hint type="destinationlabel" >
|
||||||
<x>286</x>
|
<x>286</x>
|
||||||
|
@ -19,7 +19,7 @@ from libprs500 import isosx
|
|||||||
import os, sys, textwrap, cStringIO, collections, traceback, shutil
|
import os, sys, textwrap, cStringIO, collections, traceback, shutil
|
||||||
|
|
||||||
from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, \
|
from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, \
|
||||||
QSettings, QVariant, QSize, QThread, QTimer
|
QSettings, QVariant, QSize, QThread
|
||||||
from PyQt4.QtGui import QPixmap, QColor, QPainter, QMenu, QIcon, QMessageBox, \
|
from PyQt4.QtGui import QPixmap, QColor, QPainter, QMenu, QIcon, QMessageBox, \
|
||||||
QToolButton, QDialog
|
QToolButton, QDialog
|
||||||
from PyQt4.QtSvg import QSvgRenderer
|
from PyQt4.QtSvg import QSvgRenderer
|
||||||
@ -33,7 +33,8 @@ from libprs500.devices.errors import FreeSpaceError
|
|||||||
from libprs500.devices.interface import Device
|
from libprs500.devices.interface import Device
|
||||||
from libprs500.gui2 import APP_UID, warning_dialog, choose_files, error_dialog, \
|
from libprs500.gui2 import APP_UID, warning_dialog, choose_files, error_dialog, \
|
||||||
initialize_file_icon_provider, BOOK_EXTENSIONS, \
|
initialize_file_icon_provider, BOOK_EXTENSIONS, \
|
||||||
pixmap_to_data, choose_dir, ORG_NAME, qstring_to_unicode
|
pixmap_to_data, choose_dir, ORG_NAME, \
|
||||||
|
qstring_to_unicode, set_sidebar_directories
|
||||||
from libprs500.gui2.main_window import MainWindow
|
from libprs500.gui2.main_window import MainWindow
|
||||||
from libprs500.gui2.main_ui import Ui_MainWindow
|
from libprs500.gui2.main_ui import Ui_MainWindow
|
||||||
from libprs500.gui2.device import DeviceDetector, DeviceManager
|
from libprs500.gui2.device import DeviceDetector, DeviceManager
|
||||||
@ -703,7 +704,7 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
self.library_view.set_database(self.database_path)
|
self.library_view.set_database(self.database_path)
|
||||||
self.library_view.sortByColumn(3, Qt.DescendingOrder)
|
self.library_view.sortByColumn(3, Qt.DescendingOrder)
|
||||||
self.library_view.resizeRowsToContents()
|
self.library_view.resizeRowsToContents()
|
||||||
|
set_sidebar_directories(d.directories)
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
@ -776,6 +777,7 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
self.database_path = qstring_to_unicode(settings.value("database path",
|
self.database_path = qstring_to_unicode(settings.value("database path",
|
||||||
QVariant(os.path.join(os.path.expanduser('~'),'library1.db'))).toString())
|
QVariant(os.path.join(os.path.expanduser('~'),'library1.db'))).toString())
|
||||||
|
set_sidebar_directories(None)
|
||||||
|
|
||||||
def write_settings(self):
|
def write_settings(self):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user