[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 }
BooksHints { id: globalHints }
SystemState { id: globalSystemState }
initialPage: BooksMainPage { id: mainPage }

View file

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

View file

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

View file

@ -45,10 +45,12 @@
#define KEY_FONT_SIZE "fontSize"
#define KEY_PAGE_DETAILS "pageDetails"
#define KEY_CURRENT_BOOK "currentBook"
#define KEY_CURRENT_STORAGE "currentStorage"
#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_INVERT_COLORS false
// ==========================================================================
@ -196,6 +198,7 @@ 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)),
iCurrentBookPath(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
iCurrentBook(NULL)
{
@ -204,6 +207,7 @@ BooksSettings::BooksSettings(QObject* aParent) :
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(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
}
@ -259,6 +263,20 @@ BooksSettings::setInvertColors(
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*
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(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)
class TextStyle;
public:
@ -73,12 +74,16 @@ public:
QObject* currentBook() const;
void setCurrentBook(QObject* aBook);
QString currentStorage() const;
void setCurrentStorage(QString aValue);
signals:
void fontSizeChanged();
void textStyleChanged();
void pageDetailsChanged();
void invertColorsChanged();
void currentBookChanged();
void currentStorageChanged();
private Q_SLOTS:
void onFontSizeValueChanged();
@ -92,6 +97,7 @@ private:
MGConfItem* iFontSize;
MGConfItem* iPageDetails;
MGConfItem* iInvertColors;
MGConfItem* iCurrentStorage;
MGConfItem* iCurrentBookPath;
shared_ptr<ZLTextStyle> iTextStyle;
BooksBook* iCurrentBook;

View file

@ -102,6 +102,23 @@ int BooksStorageModel::count() const
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)
{
if (validIndex(aIndex)) {

View file

@ -53,6 +53,8 @@ public:
~BooksStorageModel();
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 cancelDeleteAllRequests();
Q_INVOKABLE QObject* get(int aIndex) const;