diff --git a/sleepyhead/mainwindow.cpp b/sleepyhead/mainwindow.cpp index 34d58b75..f38ac755 100644 --- a/sleepyhead/mainwindow.cpp +++ b/sleepyhead/mainwindow.cpp @@ -390,19 +390,24 @@ void MainWindow::firstRunMessage() QString GenerateWelcomeHTML(); -void MainWindow::OpenProfile(QString profileName) +bool MainWindow::OpenProfile(QString profileName) { - Profile * prof = Profiles::profiles[profileName]; + auto pit = Profiles::profiles.find(profileName); + if (pit == Profiles::profiles.end()) return false; + + Profile * prof = pit.value(); if (p_profile) { if ((prof != p_profile)) { CloseProfile(); } else { // Already open - return; + return false; } } - if (!prof) return; - + prof = profileSelector->SelectProfile(profileName); // asks for the password and updates stuff in profileSelector tab + if (!prof) { + return false; + } // TODO: Check profile password // Check Lockfile @@ -415,14 +420,15 @@ void MainWindow::OpenProfile(QString profileName) QObject::tr("You can only work with one instance of an individual SleepyHead profile at a time.")+"\n\n"+ QObject::tr("If you are using cloud storage, make sure SleepyHead is closed and syncing has completed first on the other computer before proceeding."), QMessageBox::Cancel |QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Cancel) { - return; + return false; } } // not worried about localhost locks anymore, just silently drop it. prof->removeLock(); } - qstatus->setText(tr("Loading Data")); - qprogress->show(); + +// qstatus->setText(tr("Loading Data")); +// qprogress->show(); p_profile = prof; @@ -471,7 +477,7 @@ void MainWindow::OpenProfile(QString profileName) // Reload everything profile related if (daily) { qCritical() << "OpenProfile called with active Daily object!"; - return; + return false; } welcome = new Welcome(ui->tabWidget); ui->tabWidget->insertTab(1, welcome, tr("Welcome")); @@ -482,7 +488,7 @@ void MainWindow::OpenProfile(QString profileName) if (overview) { qCritical() << "OpenProfile called with active Overview object!"; - return; + return false; } overview = new Overview(ui->tabWidget, daily->graphView()); ui->tabWidget->insertTab(3, overview, STR_TR_Overview); @@ -496,17 +502,15 @@ void MainWindow::OpenProfile(QString profileName) AppSetting->setProfileName(p_profile->user->userName()); mainwin->setWindowTitle(STR_TR_SleepyHead + QString(" %1 (" + tr("Profile") + ": %2)").arg(getBranchVersion()).arg(AppSetting->profileName())); - profileSelector->updateProfileHighlight(profileName); - ui->oximetryButton->setDisabled(false); ui->dailyButton->setDisabled(false); ui->overviewButton->setDisabled(false); ui->statisticsButton->setDisabled(false); ui->importButton->setDisabled(false); - qprogress->hide(); - qstatus->setText(""); - + //qprogress->hide(); + //qstatus->setText(""); + return true; } void MainWindow::CloseProfile() @@ -545,11 +549,12 @@ void MainWindow::Startup() firstRunMessage(); if (Profiles::profiles.contains(lastProfile) && AppSetting->autoOpenLastUsed()) { - OpenProfile(lastProfile); - ui->tabWidget->setCurrentIndex(AppSetting->openTabAtStart()); + if (OpenProfile(lastProfile)) { + ui->tabWidget->setCurrentIndex(AppSetting->openTabAtStart()); - if (AppSetting->autoLaunchImport()) { - on_importButton_clicked(); + if (AppSetting->autoLaunchImport()) { + on_importButton_clicked(); + } } } else { ui->tabWidget->setCurrentWidget(profileSelector); diff --git a/sleepyhead/mainwindow.h b/sleepyhead/mainwindow.h index 0af886aa..06233aaa 100644 --- a/sleepyhead/mainwindow.h +++ b/sleepyhead/mainwindow.h @@ -93,7 +93,7 @@ class MainWindow : public QMainWindow void CheckForUpdates(); void CloseProfile(); - void OpenProfile(QString name); + bool OpenProfile(QString name); /*! \fn Notify(QString s,int ms=5000, QString title="SleepyHead v"+VersionString()); \brief Pops up a message box near the system tray diff --git a/sleepyhead/profileselector.cpp b/sleepyhead/profileselector.cpp index 50b4e430..d5ada8b6 100644 --- a/sleepyhead/profileselector.cpp +++ b/sleepyhead/profileselector.cpp @@ -177,36 +177,47 @@ void ProfileSelector::updateProfileList() void ProfileSelector::updateProfileHighlight(QString name) { + QFont font = QApplication::font(); font.setBold(false); QBrush bg = QColor(Qt::black); for (int row=0;row < model->rowCount(); row++) { for (int i=0; icolumnCount(); i++) { - model->setData(model->index(row, i, QModelIndex()), bg, Qt::ForegroundRole); - //model->setData(model->index(row, i, QModelIndex()), font, Qt::FontRole); + QModelIndex idx = model->index(row, i, QModelIndex()); + model->setData(idx, bg, Qt::ForegroundRole); + model->setData(idx, font, Qt::FontRole); } } + bg = QBrush(openProfileHighlightColor); - font = QApplication::font(); font.setBold(true); + for (int row=0;row < proxy->rowCount(); row++) { - if (proxy->data(proxy->index(row, 0, QModelIndex())).toString().compare(name)==0) { + QModelIndex idx = proxy->index(row, 0, QModelIndex()); + + if (proxy->data(idx).toString().compare(name)==0) { + on_selectionChanged(idx, QModelIndex()); + for (int i=0; icolumnCount(); i++) { - proxy->setData(proxy->index(row, i, QModelIndex()), bg, Qt::ForegroundRole); - // proxy->setData(model->index(row, i, QModelIndex()), font, Qt::FontRole); + idx = proxy->index(row, i, QModelIndex()); + + proxy->setData(idx, bg, Qt::ForegroundRole); + proxy->setData(idx, font, Qt::FontRole); } - on_selectionChanged(proxy->index(row, 0, QModelIndex()), QModelIndex()); break; } } } -void ProfileSelector::SelectProfile(QString profname) +Profile *ProfileSelector::SelectProfile(QString profname) { qDebug() << "Selecting new profile" << profname; - Profile * prof = Profiles::profiles[profname]; + auto pit = Profiles::profiles.find(profname); + if (pit == Profiles::profiles.end()) return nullptr; + + Profile * prof = pit.value(); if (prof != p_profile) { if (prof->user->hasPassword()) { @@ -242,16 +253,15 @@ void ProfileSelector::SelectProfile(QString profname) } } } while (tries < 3); - if (!succeeded) return; + if (!succeeded) return nullptr; } // Unselect everything in ProfileView - mainwin->OpenProfile(profname); updateProfileHighlight(profname); - } + return prof; } void ProfileSelector::on_profileView_doubleClicked(const QModelIndex &index) @@ -259,7 +269,9 @@ void ProfileSelector::on_profileView_doubleClicked(const QModelIndex &index) QModelIndex idx = proxy->index(index.row(), 0, QModelIndex()); QString profname = proxy->data(idx, Qt::UserRole+2).toString(); - SelectProfile(profname); + //if (SelectProfile(profname)) { + mainwin->OpenProfile(profname); + //} } void ProfileSelector::on_profileFilter_textChanged(const QString &arg1) diff --git a/sleepyhead/profileselector.h b/sleepyhead/profileselector.h index a51040d8..9f52d692 100644 --- a/sleepyhead/profileselector.h +++ b/sleepyhead/profileselector.h @@ -13,6 +13,8 @@ #include #include +#include "SleepLib/profiles.h" + namespace Ui { class ProfileSelector; } @@ -35,7 +37,7 @@ public: ~ProfileSelector(); void updateProfileList(); - void SelectProfile(QString profname); + Profile *SelectProfile(QString profname); void updateProfileHighlight(QString name); private slots: