[app] Select the last used storage at startup

This commit is contained in:
Slava Monich 2015-08-19 00:35:34 +03:00
parent 033f54492e
commit 450156f2b8
7 changed files with 61 additions and 4 deletions

View file

@ -41,6 +41,7 @@ ApplicationWindow {
BooksSettings { id: globalSettings } BooksSettings { id: globalSettings }
BooksHints { id: globalHints } BooksHints { id: globalHints }
SystemState { id: globalSystemState }
initialPage: BooksMainPage { id: mainPage } initialPage: BooksMainPage { id: mainPage }

View file

@ -115,9 +115,9 @@ SilicaFlickable {
} }
} }
SystemState { Connections {
id: globalSystemState target: globalSystemState
onLockModeChanged: if (lockMode == "locked") editMode = false onLockModeChanged: if (target.lockMode === "locked") editMode = false
} }
BookStorage { BookStorage {
@ -132,6 +132,11 @@ SilicaFlickable {
id: storageListWatcher id: storageListWatcher
listView: storageList listView: storageList
onSizeChanged: _cellWidth = calculateCellWidth() onSizeChanged: _cellWidth = calculateCellWidth()
onCurrentIndexChanged: {
if (storageList._completed && currentIndex >= 0) {
globalSettings.currentStorage = storageModel.deviceAt(currentIndex)
}
}
} }
SilicaListView { SilicaListView {
@ -144,6 +149,7 @@ SilicaFlickable {
spacing: Theme.paddingMedium spacing: Theme.paddingMedium
interactive: !dragInProgress && !dragScrollAnimation.running interactive: !dragInProgress && !dragScrollAnimation.running
property bool _completed
readonly property real maxContentX: Math.max(0, contentWidth - width) readonly property real maxContentX: Math.max(0, contentWidth - width)
onMaxContentXChanged: { onMaxContentXChanged: {
@ -154,6 +160,13 @@ 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
}
delegate: BooksShelfView { delegate: BooksShelfView {
width: storageList.width width: storageList.width
height: storageList.height height: storageList.height

View file

@ -41,7 +41,7 @@
BooksListWatcher::BooksListWatcher(QObject* aParent) : BooksListWatcher::BooksListWatcher(QObject* aParent) :
QObject(aParent), QObject(aParent),
iCurrentIndex(0), iCurrentIndex(-1),
iContentX(0), iContentX(0),
iContentY(0), iContentY(0),
iListView(NULL), iListView(NULL),

View file

@ -45,10 +45,12 @@
#define KEY_FONT_SIZE "fontSize" #define KEY_FONT_SIZE "fontSize"
#define KEY_PAGE_DETAILS "pageDetails" #define KEY_PAGE_DETAILS "pageDetails"
#define KEY_CURRENT_BOOK "currentBook" #define KEY_CURRENT_BOOK "currentBook"
#define KEY_CURRENT_STORAGE "currentStorage"
#define KEY_INVERT_COLORS "invertColors" #define KEY_INVERT_COLORS "invertColors"
#define DEFAULT_FONT_SIZE 0 #define DEFAULT_FONT_SIZE 0
#define DEFAULT_PAGE_DETAILS 0 #define DEFAULT_PAGE_DETAILS 0
#define DEFAULT_CURRENT_BOOK QString() #define DEFAULT_CURRENT_BOOK QString()
#define DEFAULT_CURRENT_STORAGE QString()
#define DEFAULT_INVERT_COLORS false #define DEFAULT_INVERT_COLORS false
// ========================================================================== // ==========================================================================
@ -196,6 +198,7 @@ BooksSettings::BooksSettings(QObject* aParent) :
iFontSize(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)), iFontSize(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
iPageDetails(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)), iPageDetails(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)),
iInvertColors(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)), iInvertColors(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
iCurrentStorage(new MGConfItem(DCONF_PATH KEY_CURRENT_STORAGE, this)),
iCurrentBookPath(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)), iCurrentBookPath(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
iCurrentBook(NULL) iCurrentBook(NULL)
{ {
@ -204,6 +207,7 @@ BooksSettings::BooksSettings(QObject* aParent) :
connect(iFontSize, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged())); connect(iFontSize, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged()));
connect(iPageDetails, SIGNAL(valueChanged()), SIGNAL(pageDetailsChanged())); connect(iPageDetails, SIGNAL(valueChanged()), SIGNAL(pageDetailsChanged()));
connect(iInvertColors, SIGNAL(valueChanged()), SIGNAL(invertColorsChanged())); connect(iInvertColors, SIGNAL(valueChanged()), SIGNAL(invertColorsChanged()));
connect(iCurrentStorage, SIGNAL(valueChanged()), SIGNAL(currentStorageChanged()));
connect(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged())); connect(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
} }
@ -259,6 +263,20 @@ BooksSettings::setInvertColors(
iInvertColors->set(aValue); iInvertColors->set(aValue);
} }
QString
BooksSettings::currentStorage() const
{
return iCurrentStorage->value(DEFAULT_CURRENT_STORAGE).toString();
}
void
BooksSettings::setCurrentStorage(
QString aValue)
{
HDEBUG(aValue);
iCurrentStorage->set(aValue);
}
QObject* QObject*
BooksSettings::currentBook() const BooksSettings::currentBook() const
{ {

View file

@ -48,6 +48,7 @@ class BooksSettings : public QObject
Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged) Q_PROPERTY(int pageDetails READ pageDetails WRITE setPageDetails NOTIFY pageDetailsChanged)
Q_PROPERTY(bool invertColors READ invertColors WRITE setInvertColors NOTIFY invertColorsChanged) Q_PROPERTY(bool invertColors READ invertColors WRITE setInvertColors NOTIFY invertColorsChanged)
Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged) Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged)
Q_PROPERTY(QString currentStorage READ currentStorage WRITE setCurrentStorage NOTIFY currentStorageChanged)
class TextStyle; class TextStyle;
public: public:
@ -73,12 +74,16 @@ public:
QObject* currentBook() const; QObject* currentBook() const;
void setCurrentBook(QObject* aBook); void setCurrentBook(QObject* aBook);
QString currentStorage() const;
void setCurrentStorage(QString aValue);
signals: signals:
void fontSizeChanged(); void fontSizeChanged();
void textStyleChanged(); void textStyleChanged();
void pageDetailsChanged(); void pageDetailsChanged();
void invertColorsChanged(); void invertColorsChanged();
void currentBookChanged(); void currentBookChanged();
void currentStorageChanged();
private Q_SLOTS: private Q_SLOTS:
void onFontSizeValueChanged(); void onFontSizeValueChanged();
@ -92,6 +97,7 @@ private:
MGConfItem* iFontSize; MGConfItem* iFontSize;
MGConfItem* iPageDetails; MGConfItem* iPageDetails;
MGConfItem* iInvertColors; MGConfItem* iInvertColors;
MGConfItem* iCurrentStorage;
MGConfItem* iCurrentBookPath; MGConfItem* iCurrentBookPath;
shared_ptr<ZLTextStyle> iTextStyle; shared_ptr<ZLTextStyle> iTextStyle;
BooksBook* iCurrentBook; BooksBook* iCurrentBook;

View file

@ -102,6 +102,23 @@ int BooksStorageModel::count() const
return iList.count(); return iList.count();
} }
int BooksStorageModel::deviceIndex(QString aDevice) const
{
if (!aDevice.isEmpty()) {
for (int i=iList.count()-1; i>=0; i--) {
if (iList.at(i)->device() == aDevice) {
return i;
}
}
}
return -1;
}
QString BooksStorageModel::deviceAt(int aIndex) const
{
return validIndex(aIndex) ? iList.at(aIndex)->device() : QString();
}
void BooksStorageModel::setDeleteAllRequest(int aIndex, bool aValue) void BooksStorageModel::setDeleteAllRequest(int aIndex, bool aValue)
{ {
if (validIndex(aIndex)) { if (validIndex(aIndex)) {

View file

@ -53,6 +53,8 @@ public:
~BooksStorageModel(); ~BooksStorageModel();
Q_INVOKABLE int count() const; Q_INVOKABLE int count() const;
Q_INVOKABLE int deviceIndex(QString aDevice) const;
Q_INVOKABLE QString deviceAt(int aIndex) const;
Q_INVOKABLE void setDeleteAllRequest(int aIndex, bool aValue); Q_INVOKABLE void setDeleteAllRequest(int aIndex, bool aValue);
Q_INVOKABLE void cancelDeleteAllRequests(); Q_INVOKABLE void cancelDeleteAllRequests();
Q_INVOKABLE QObject* get(int aIndex) const; Q_INVOKABLE QObject* get(int aIndex) const;