[app] Store the current directory in dconf, not just the mountpoint

This will play better with the folder support when it gets implemented.
This commit is contained in:
Slava Monich 2015-08-19 18:18:25 +03:00
parent ae06b6f808
commit 87ebcecd28
3 changed files with 56 additions and 20 deletions

View file

@ -81,6 +81,12 @@ SilicaFlickable {
Component.onCompleted: _cellWidth = calculateCellWidth()
onCurrentShelfChanged: {
if (storageList.completed && currentShelf) {
globalSettings.currentFolder = currentShelf.path
}
}
PullDownMenu {
MenuItem {
//% "Scan downloads"
@ -132,11 +138,6 @@ SilicaFlickable {
id: storageListWatcher
listView: storageList
onSizeChanged: _cellWidth = calculateCellWidth()
onCurrentIndexChanged: {
if (storageList._completed && currentIndex >= 0) {
globalSettings.currentStorage = storageModel.deviceAt(currentIndex)
}
}
}
SilicaListView {
@ -149,7 +150,7 @@ SilicaFlickable {
spacing: Theme.paddingMedium
interactive: !dragInProgress && !dragScrollAnimation.running
property bool _completed
property bool completed
readonly property real maxContentX: Math.max(0, contentWidth - width)
onMaxContentXChanged: {
@ -163,8 +164,14 @@ SilicaFlickable {
Component.onCompleted: {
var index = model.deviceIndex(globalSettings.currentStorage)
// positionViewAtIndex doesn't work here, update contentX directly
if (index >= 0) contentX = (width + spacing) * index
_completed = true
if (index >= 0) {
contentX = (width + spacing) * index
} else {
// Most likely, removable storage is gone
console.log(globalSettings.currentFolder, "is gone")
globalSettings.currentFolder = currentShelf ? currentShelf.path : ""
}
completed = true
}
delegate: BooksShelfView {

View file

@ -45,12 +45,12 @@
#define KEY_FONT_SIZE "fontSize"
#define KEY_PAGE_DETAILS "pageDetails"
#define KEY_CURRENT_BOOK "currentBook"
#define KEY_CURRENT_STORAGE "currentStorage"
#define KEY_CURRENT_FOLDER "currentFolder"
#define KEY_INVERT_COLORS "invertColors"
#define DEFAULT_FONT_SIZE 0
#define DEFAULT_PAGE_DETAILS 0
#define DEFAULT_CURRENT_BOOK QString()
#define DEFAULT_CURRENT_STORAGE QString()
#define DEFAULT_CURRENT_FOLDER QString()
#define DEFAULT_INVERT_COLORS false
// ==========================================================================
@ -198,16 +198,17 @@ BooksSettings::BooksSettings(QObject* aParent) :
iFontSize(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
iPageDetails(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)),
iInvertColors(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
iCurrentStorage(new MGConfItem(DCONF_PATH KEY_CURRENT_STORAGE, this)),
iCurrentFolder(new MGConfItem(DCONF_PATH KEY_CURRENT_FOLDER, this)),
iCurrentBookPath(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
iCurrentBook(NULL)
{
iTextStyle = new TextStyle(fontSize());
updateCurrentBook();
updateCurrentStorage();
connect(iFontSize, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged()));
connect(iPageDetails, SIGNAL(valueChanged()), SIGNAL(pageDetailsChanged()));
connect(iInvertColors, SIGNAL(valueChanged()), SIGNAL(invertColorsChanged()));
connect(iCurrentStorage, SIGNAL(valueChanged()), SIGNAL(currentStorageChanged()));
connect(iCurrentFolder, SIGNAL(valueChanged()), SLOT(onCurrentFolderChanged()));
connect(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
}
@ -264,17 +265,38 @@ BooksSettings::setInvertColors(
}
QString
BooksSettings::currentStorage() const
BooksSettings::currentFolder() const
{
return iCurrentStorage->value(DEFAULT_CURRENT_STORAGE).toString();
return iCurrentFolder->value(DEFAULT_CURRENT_FOLDER).toString();
}
void
BooksSettings::setCurrentStorage(
BooksSettings::setCurrentFolder(
QString aValue)
{
HDEBUG(aValue);
iCurrentStorage->set(aValue);
iCurrentFolder->set(aValue);
}
void
BooksSettings::onCurrentFolderChanged()
{
if (updateCurrentStorage()) {
Q_EMIT currentStorageChanged();
}
Q_EMIT currentFolderChanged();
}
bool
BooksSettings::updateCurrentStorage()
{
BooksStorageManager* mgr = BooksStorageManager::instance();
BooksStorage storage = mgr->storageForPath(currentFolder());
if (storage.isValid() && storage.device() != iCurrentStorageDevice) {
iCurrentStorageDevice = storage.device();
return true;
}
return false;
}
QObject*

View file

@ -48,7 +48,8 @@ class BooksSettings : public QObject
Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged)
Q_PROPERTY(bool invertColors READ invertColors WRITE setInvertColors NOTIFY invertColorsChanged)
Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged)
Q_PROPERTY(QString currentStorage READ currentStorage WRITE setCurrentStorage NOTIFY currentStorageChanged)
Q_PROPERTY(QString currentFolder READ currentFolder WRITE setCurrentFolder NOTIFY currentFolderChanged)
Q_PROPERTY(QString currentStorage READ currentStorage NOTIFY currentStorageChanged)
class TextStyle;
public:
@ -74,8 +75,10 @@ public:
QObject* currentBook() const;
void setCurrentBook(QObject* aBook);
QString currentStorage() const;
void setCurrentStorage(QString aValue);
QString currentFolder() const;
void setCurrentFolder(QString aValue);
QString currentStorage() const { return iCurrentStorageDevice; }
signals:
void fontSizeChanged();
@ -83,24 +86,28 @@ signals:
void pageDetailsChanged();
void invertColorsChanged();
void currentBookChanged();
void currentFolderChanged();
void currentStorageChanged();
private Q_SLOTS:
void onFontSizeValueChanged();
void onCurrentBookPathChanged();
void onCurrentFolderChanged();
private:
void updateRenderType();
bool updateCurrentBook();
bool updateCurrentStorage();
private:
MGConfItem* iFontSize;
MGConfItem* iPageDetails;
MGConfItem* iInvertColors;
MGConfItem* iCurrentStorage;
MGConfItem* iCurrentFolder;
MGConfItem* iCurrentBookPath;
shared_ptr<ZLTextStyle> iTextStyle;
BooksBook* iCurrentBook;
QString iCurrentStorageDevice;
};
QML_DECLARE_TYPE(BooksSettings)