Make profile selection a little smarter

This commit is contained in:
Mark Watkins 2018-06-05 09:26:46 +10:00
parent 3ff9ad1469
commit f794dbd1d3
17 changed files with 153 additions and 88 deletions

View File

@ -3,8 +3,8 @@
* Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net> * Copyright (C) 2011-2018 Mark Watkins <mark@jedimark.net>
* *
* This file is subject to the terms and conditions of the GNU General Public * This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of the Linux * License. See the file COPYING in the main directory of the source code
* distribution for more details. */ * for more details. */
#ifndef CMS50LOADER_H #ifndef CMS50LOADER_H
#define CMS50LOADER_H #define CMS50LOADER_H

View File

@ -16,8 +16,8 @@
const QString FPHCARE = "FPHCARE"; const QString FPHCARE = "FPHCARE";
FPIcon::FPIcon(MachineID id) FPIcon::FPIcon(Profile *profile, MachineID id)
: CPAP(id) : CPAP(profile, id)
{ {
} }

View File

@ -30,7 +30,7 @@ const int fpicon_data_version = 3;
class FPIcon: public CPAP class FPIcon: public CPAP
{ {
public: public:
FPIcon(MachineID id = 0); FPIcon(Profile *, MachineID id = 0);
virtual ~FPIcon(); virtual ~FPIcon();
}; };

View File

@ -14,8 +14,8 @@
ChannelID INTP_SmartFlexMode, INTP_SmartFlexLevel; ChannelID INTP_SmartFlexMode, INTP_SmartFlexLevel;
Intellipap::Intellipap(MachineID id) Intellipap::Intellipap(Profile *profile, MachineID id)
: CPAP(id) : CPAP(profile, id)
{ {
} }

View File

@ -29,7 +29,7 @@ const int intellipap_data_version = 3;
class Intellipap: public CPAP class Intellipap: public CPAP
{ {
public: public:
Intellipap(MachineID id = 0); Intellipap(Profile *, MachineID id = 0);
virtual ~Intellipap(); virtual ~Intellipap();
}; };

View File

@ -14,8 +14,8 @@ extern QProgressBar *qprogress;
MSeries::MSeries(MachineID id) MSeries::MSeries(Profile *profile, MachineID id)
: CPAP(id) : CPAP(profile, id)
{ {
} }

View File

@ -31,7 +31,7 @@ const int mseries_data_version = 2;
class MSeries: public CPAP class MSeries: public CPAP
{ {
public: public:
MSeries(MachineID id = 0); MSeries(Profile *, MachineID id = 0);
virtual ~MSeries(); virtual ~MSeries();
}; };

View File

@ -3,8 +3,8 @@
* Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net> * Copyright (c) 2011-2018 Mark Watkins <mark@jedimark.net>
* *
* This file is subject to the terms and conditions of the GNU General Public * This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of the Linux * License. See the file COPYING in the main directory of the source code
* distribution for more details. */ * for more details. */
#include <QApplication> #include <QApplication>
#include <QString> #include <QString>
@ -102,7 +102,7 @@ enum FlexMode { FLEX_None, FLEX_CFlex, FLEX_CFlexPlus, FLEX_AFlex, FLEX_RiseTime
ChannelID PRS1_TimedBreath = 0, PRS1_HeatedTubing = 0; ChannelID PRS1_TimedBreath = 0, PRS1_HeatedTubing = 0;
PRS1::PRS1(MachineID id): CPAP(id) PRS1::PRS1(Profile *profile, MachineID id): CPAP(profile, id)
{ {
} }
PRS1::~PRS1() PRS1::~PRS1()

View File

@ -30,7 +30,7 @@ const int prs1_data_version = 15;
class PRS1: public CPAP class PRS1: public CPAP
{ {
public: public:
PRS1(MachineID id = 0); PRS1(Profile *, MachineID id = 0);
virtual ~PRS1(); virtual ~PRS1();
}; };

View File

@ -18,8 +18,8 @@
extern QProgressBar *qprogress; extern QProgressBar *qprogress;
Weinmann::Weinmann(MachineID id) Weinmann::Weinmann(Profile *profile, MachineID id)
: CPAP(id) : CPAP(profile, id)
{ {
} }

View File

@ -29,7 +29,7 @@ const int weinmann_data_version = 3;
class Weinmann: public CPAP class Weinmann: public CPAP
{ {
public: public:
Weinmann(MachineID id = 0); Weinmann(Profile *, MachineID id = 0);
virtual ~Weinmann(); virtual ~Weinmann();
}; };

View File

@ -41,7 +41,7 @@ extern QProgressBar *qprogress;
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// Machine Base-Class implmementation // Machine Base-Class implmementation
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
Machine::Machine(MachineID id) Machine::Machine(Profile *_profile, MachineID id) : profile(_profile)
{ {
day.clear(); day.clear();
highest_sessionid = 0; highest_sessionid = 0;
@ -57,8 +57,8 @@ Machine::Machine(MachineID id)
temp = rand(); temp = rand();
found = false; found = false;
for (int i=0;i<p_profile->m_machlist.size(); ++i) { for (int i=0;i<profile->m_machlist.size(); ++i) {
if (p_profile->m_machlist.at(i)->id() == temp) found = true; if (profile->m_machlist.at(i)->id() == temp) found = true;
} }
} while (found); } while (found);
@ -198,8 +198,8 @@ bool Machine::loadSessionInfo()
// Find date this session belongs in // Find date this session belongs in
QDate Machine::pickDate(qint64 first) QDate Machine::pickDate(qint64 first)
{ {
QTime split_time = p_profile->session->daySplitTime(); QTime split_time = profile->session->daySplitTime();
int combine_sessions = p_profile->session->combineCloseSessions(); int combine_sessions = profile->session->combineCloseSessions();
QDateTime d2 = QDateTime::fromTime_t(first / 1000); QDateTime d2 = QDateTime::fromTime_t(first / 1000);
@ -232,13 +232,13 @@ bool Machine::AddSession(Session *s)
qCritical() << "AddSession() called with a null object"; qCritical() << "AddSession() called with a null object";
return false; return false;
} }
if (p_profile == nullptr) { if (profile == nullptr) {
qCritical() << "AddSession() called without a valid p_profile"; qCritical() << "AddSession() called without a valid profile";
return false; return false;
} }
if (p_profile->session->ignoreOlderSessions()) { if (profile->session->ignoreOlderSessions()) {
qint64 ignorebefore = p_profile->session->ignoreOlderSessionsDate().toMSecsSinceEpoch(); qint64 ignorebefore = profile->session->ignoreOlderSessionsDate().toMSecsSinceEpoch();
if (s->last() < ignorebefore) { if (s->last() < ignorebefore) {
skipped_sessions++; skipped_sessions++;
return false; return false;
@ -254,24 +254,24 @@ bool Machine::AddSession(Session *s)
QTime split_time; QTime split_time;
int combine_sessions; int combine_sessions;
bool locksessions = p_profile->session->lockSummarySessions(); bool locksessions = profile->session->lockSummarySessions();
if (locksessions) { if (locksessions) {
split_time = s->summaryOnly() ? QTime(12,0,0) : p_profile->session->daySplitTime(); split_time = s->summaryOnly() ? QTime(12,0,0) : profile->session->daySplitTime();
combine_sessions = s->summaryOnly() ? 0 : p_profile->session->combineCloseSessions(); combine_sessions = s->summaryOnly() ? 0 : p_profile->session->combineCloseSessions();
} else { } else {
split_time = p_profile->session->daySplitTime(); split_time = profile->session->daySplitTime();
combine_sessions = p_profile->session->combineCloseSessions(); combine_sessions = profile->session->combineCloseSessions();
} }
int ignore_sessions = p_profile->session->ignoreShortSessions(); int ignore_sessions = profile->session->ignoreShortSessions();
int session_length = s->last() - s->first(); int session_length = s->last() - s->first();
session_length /= 60000; session_length /= 60000;
sessionlist[s->session()] = s; // To make sure it get's saved later even if it's not wanted. sessionlist[s->session()] = s; // To make sure it get's saved later even if it's not wanted.
//int drift=p_profile->cpap->clockDrift(); //int drift=profile->cpap->clockDrift();
QDateTime d2 = QDateTime::fromTime_t(s->first() / 1000); QDateTime d2 = QDateTime::fromTime_t(s->first() / 1000);
@ -338,7 +338,7 @@ bool Machine::AddSession(Session *s)
dit = day.find(date); dit = day.find(date);
if (dit == day.end()) { if (dit == day.end()) {
dit = day.insert(date, p_profile->addDay(date)); dit = day.insert(date, profile->addDay(date));
} }
dd = dit.value(); dd = dit.value();
@ -356,9 +356,9 @@ bool Machine::AddSession(Session *s)
dd->addSession(*i); dd->addSession(*i);
} }
// QMap<QDate, QList<Day *> >::iterator nd = p_profile->daylist.find(date.addDays(1)); // QMap<QDate, QList<Day *> >::iterator nd = profile->daylist.find(date.addDays(1));
// if (nd != p_profile->daylist.end()) { // if (nd != profile->daylist.end()) {
// p_profile->unlinkDay(nd.key(), nd.value()); // profile->unlinkDay(nd.key(), nd.value());
// } // }
// QList<Day *>::iterator iend = nd.value().end(); // QList<Day *>::iterator iend = nd.value().end();
@ -425,7 +425,7 @@ bool Machine::unlinkSession(Session * sess)
} }
if (d->size() == 0) { if (d->size() == 0) {
p_profile->unlinkDay(d); profile->unlinkDay(d);
} }
} }
} }
@ -457,7 +457,7 @@ bool Machine::Purge(int secret)
QFile impfile(getDataPath()+"/imported_files.csv"); QFile impfile(getDataPath()+"/imported_files.csv");
impfile.remove(); impfile.remove();
QFile rxcache(p_profile->Get("{" + STR_GEN_DataFolder + "}/RXChanges.cache" )); QFile rxcache(profile->Get("{" + STR_GEN_DataFolder + "}/RXChanges.cache" ));
rxcache.remove(); rxcache.remove();
QFile sumfile(getDataPath()+"/Summaries.xml.gz"); QFile sumfile(getDataPath()+"/Summaries.xml.gz");
@ -546,7 +546,7 @@ void Machine::setInfo(MachineInfo inf)
const QString Machine::getDataPath() const QString Machine::getDataPath()
{ {
if (m_dataPath.isEmpty()) { if (m_dataPath.isEmpty()) {
m_dataPath = p_profile->Get("{" + STR_GEN_DataFolder + "}/" + info.loadername + "_" + (info.serial.isEmpty() ? hexid() : info.serial)) + "/"; m_dataPath = profile->Get("{" + STR_GEN_DataFolder + "}/" + info.loadername + "_" + (info.serial.isEmpty() ? hexid() : info.serial)) + "/";
} }
return m_dataPath; return m_dataPath;
} }
@ -558,10 +558,9 @@ const QString Machine::getEventsPath()
{ {
return getDataPath() + "Events/"; return getDataPath() + "Events/";
} }
const QString Machine::getBackupPath() const QString Machine::getBackupPath()
{ {
return p_profile->Get("{" + STR_GEN_DataFolder + "}/" + info.loadername + "_" + (info.serial.isEmpty() ? hexid() : info.serial) + "/Backup/"); return getDataPath() + "Backup/";
} }
// dirSize lazily pinched from https://stackoverflow.com/questions/47854288/can-not-get-directory-size-in-qt-c, thank's "Mike" // dirSize lazily pinched from https://stackoverflow.com/questions/47854288/can-not-get-directory-size-in-qt-c, thank's "Mike"
@ -610,7 +609,7 @@ bool Machine::Load()
QPixmap image = getPixmap().scaled(64,64); QPixmap image = getPixmap().scaled(64,64);
popup->setPixmap(image); popup->setPixmap(image);
popup->setMessage(QObject::tr("Loading %1 data for %2...").arg(info.brand).arg(p_profile->user->userName())); popup->setMessage(QObject::tr("Loading %1 data for %2...").arg(info.brand).arg(profile->user->userName()));
popup->open(); popup->open();
QProgressBar * saveQProgress = qprogress; QProgressBar * saveQProgress = qprogress;
@ -1050,7 +1049,7 @@ bool Machine::LoadSummary(QProgressBar * progress)
QMap<qint64, Session *>::iterator it_end = sess_order.end(); QMap<qint64, Session *>::iterator it_end = sess_order.end();
QMap<qint64, Session *>::iterator it; QMap<qint64, Session *>::iterator it;
int cnt = 0; int cnt = 0;
bool loadSummaries = p_profile->session->preloadSummaries(); bool loadSummaries = profile->session->preloadSummaries();
progress->setMaximum(sess_order.size()); progress->setMaximum(sess_order.size());
for (it = sess_order.begin(); it != it_end; ++it, ++cnt) { for (it = sess_order.begin(); it != it_end; ++it, ++cnt) {
@ -1086,7 +1085,7 @@ bool Machine::SaveSummaryCache()
QDomElement root = doc.createElement("sessions"); QDomElement root = doc.createElement("sessions");
root.setAttribute("version", summaryxml_version); root.setAttribute("version", summaryxml_version);
root.setAttribute("profile", p_profile->user->userName()); root.setAttribute("profile", profile->user->userName());
root.setAttribute("count", sessionlist.size()); root.setAttribute("count", sessionlist.size());
root.setAttribute("loader", info.loadername); root.setAttribute("loader", info.loadername);
root.setAttribute("serial", info.serial); root.setAttribute("serial", info.serial);
@ -1220,7 +1219,7 @@ QList<ChannelID> Machine::availableChannels(quint32 chantype)
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// CPAP implmementation // CPAP implmementation
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
CPAP::CPAP(MachineID id): Machine(id) CPAP::CPAP(Profile * profile, MachineID id): Machine(profile, id)
{ {
m_type = MT_CPAP; m_type = MT_CPAP;
} }
@ -1232,7 +1231,7 @@ CPAP::~CPAP()
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// Oximeter Class implmementation // Oximeter Class implmementation
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
Oximeter::Oximeter(MachineID id): Machine(id) Oximeter::Oximeter(Profile * profile, MachineID id): Machine(profile, id)
{ {
m_type = MT_OXIMETER; m_type = MT_OXIMETER;
} }
@ -1244,7 +1243,7 @@ Oximeter::~Oximeter()
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// SleepStage Class implmementation // SleepStage Class implmementation
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
SleepStage::SleepStage(MachineID id): Machine(id) SleepStage::SleepStage(Profile * profile, MachineID id): Machine(profile, id)
{ {
m_type = MT_SLEEPSTAGE; m_type = MT_SLEEPSTAGE;
} }
@ -1255,7 +1254,7 @@ SleepStage::~SleepStage()
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// PositionSensor Class implmementation // PositionSensor Class implmementation
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
PositionSensor::PositionSensor(MachineID id): Machine(id) PositionSensor::PositionSensor(Profile * profile, MachineID id): Machine(profile, id)
{ {
m_type = MT_POSITION; m_type = MT_POSITION;
} }

View File

@ -83,7 +83,7 @@ class Machine
If supplied MachineID is zero, it will generate a new unused random one. If supplied MachineID is zero, it will generate a new unused random one.
*/ */
Machine(MachineID id = 0); Machine(Profile * _profile, MachineID id = 0);
virtual ~Machine(); virtual ~Machine();
//! \brief Load all Machine summary data //! \brief Load all Machine summary data
@ -268,6 +268,8 @@ class Machine
QString m_summaryPath; QString m_summaryPath;
QString m_eventsPath; QString m_eventsPath;
QString m_dataPath; QString m_dataPath;
Profile * profile;
}; };
@ -277,7 +279,7 @@ class Machine
class CPAP: public Machine class CPAP: public Machine
{ {
public: public:
CPAP(MachineID id = 0); CPAP(Profile *, MachineID id = 0);
virtual ~CPAP(); virtual ~CPAP();
}; };
@ -289,7 +291,7 @@ class CPAP: public Machine
class Oximeter: public Machine class Oximeter: public Machine
{ {
public: public:
Oximeter(MachineID id = 0); Oximeter(Profile *, MachineID id = 0);
virtual ~Oximeter(); virtual ~Oximeter();
protected: protected:
}; };
@ -300,7 +302,7 @@ class Oximeter: public Machine
class SleepStage: public Machine class SleepStage: public Machine
{ {
public: public:
SleepStage(MachineID id = 0); SleepStage(Profile *, MachineID id = 0);
virtual ~SleepStage(); virtual ~SleepStage();
protected: protected:
}; };
@ -311,7 +313,7 @@ class SleepStage: public Machine
class PositionSensor: public Machine class PositionSensor: public Machine
{ {
public: public:
PositionSensor(MachineID id = 0); PositionSensor(Profile *, MachineID id = 0);
virtual ~PositionSensor(); virtual ~PositionSensor();
protected: protected:
}; };

View File

@ -674,23 +674,23 @@ Machine * Profile::CreateMachine(MachineInfo info, MachineID id)
switch (info.type) { switch (info.type) {
case MT_CPAP: case MT_CPAP:
m = new CPAP(id); m = new CPAP(this, id);
break; break;
case MT_SLEEPSTAGE: case MT_SLEEPSTAGE:
m = new SleepStage(id); m = new SleepStage(this, id);
break; break;
case MT_OXIMETER: case MT_OXIMETER:
m = new Oximeter(id); m = new Oximeter(this, id);
break; break;
case MT_POSITION: case MT_POSITION:
m = new PositionSensor(id); m = new PositionSensor(this, id);
break; break;
case MT_JOURNAL: case MT_JOURNAL:
m = new Machine(id); m = new Machine(this, id);
m->setType(MT_JOURNAL); m->setType(MT_JOURNAL);
break; break;
default: default:
m = new Machine(id); m = new Machine(this, id);
break; break;
} }

View File

@ -51,15 +51,21 @@ ProfileSelector::ProfileSelector(QWidget *parent) :
model = nullptr; model = nullptr;
proxy = nullptr; proxy = nullptr;
showDiskUsage = false; showDiskUsage = false; // in case I want to preference it later
on_diskSpaceInfo_linkActivated(showDiskUsage ? "show" : "hide"); on_diskSpaceInfo_linkActivated(showDiskUsage ? "show" : "hide");
ui->versionLabel->setText(VersionString); ui->versionLabel->setText(VersionString);
ui->diskSpaceInfo->setVisible(false); ui->diskSpaceInfo->setVisible(false);
QItemSelectionModel * sm = ui->profileView->selectionModel();
connect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_selectionChanged(QModelIndex,QModelIndex)));
ui->buttonEditProfile->setEnabled(false);
} }
ProfileSelector::~ProfileSelector() ProfileSelector::~ProfileSelector()
{ {
QItemSelectionModel * sm = ui->profileView->selectionModel();
disconnect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_selectionChanged(QModelIndex,QModelIndex)));
delete ui; delete ui;
} }
@ -87,6 +93,19 @@ void ProfileSelector::updateProfileList()
// int sel = -1; // int sel = -1;
QFontMetrics fm(ui->profileView->font()); QFontMetrics fm(ui->profileView->font());
//#if QT_VERSION < QT_VERSION_CHECK(5,11,0) // not sure when this was fixed
QPalette palette = ui->profileView->palette();
palette.setColor(QPalette::Highlight, "#3a7fc2");
palette.setColor(QPalette::HighlightedText, "white");
ui->profileView->setPalette(palette);
//#endif
ui->profileView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->profileView->setFocusPolicy(Qt::NoFocus);
// ui->profileView->setSelectionMode(QAbstractItemView::NoSelection);
ui->profileView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->profileView->setSelectionMode(QAbstractItemView::SingleSelection);
QMap<QString, Profile *>::iterator pi; QMap<QString, Profile *>::iterator pi;
for (pi = Profiles::profiles.begin(); pi != Profiles::profiles.end(); pi++) { for (pi = Profiles::profiles.begin(); pi != Profiles::profiles.end(); pi++) {
@ -145,19 +164,14 @@ void ProfileSelector::updateProfileList()
proxy->setSortCaseSensitivity(Qt::CaseInsensitive); proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
ui->profileView->setModel(proxy); ui->profileView->setModel(proxy);
ui->profileView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->profileView->setSelectionMode(QAbstractItemView::SingleSelection);
QHeaderView *headerView = ui->profileView->horizontalHeader(); QHeaderView *headerView = ui->profileView->horizontalHeader();
headerView->setStretchLastSection(true); headerView->setStretchLastSection(true);
headerView->setSectionResizeMode(QHeaderView::Stretch); headerView->setSectionResizeMode(QHeaderView::Stretch);
QPalette* palette = new QPalette(); QItemSelectionModel * sm = ui->profileView->selectionModel();
palette->setColor(QPalette::Highlight,QColor("#3a7fc2")); disconnect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_selectionChanged(QModelIndex,QModelIndex)));
palette->setColor(QPalette::HighlightedText, QColor("white")); connect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(on_selectionChanged(QModelIndex,QModelIndex)));
ui->profileView->setPalette(*palette);
} }
@ -184,7 +198,7 @@ void ProfileSelector::updateProfileHighlight(QString name)
break; break;
} }
} }
if (p_profile) { /*if (p_profile) {
QString html = QString(); QString html = QString();
if (!p_profile->user->lastName().isEmpty() && !p_profile->user->firstName().isEmpty()) { if (!p_profile->user->lastName().isEmpty() && !p_profile->user->firstName().isEmpty()) {
@ -206,11 +220,9 @@ void ProfileSelector::updateProfileHighlight(QString name)
ui->diskSpaceInfo->setVisible(true); ui->diskSpaceInfo->setVisible(true);
ui->profileInfoGroupBox->setTitle(tr("Current Profile: %1").arg(name)); ui->profileInfoGroupBox->setTitle(tr("Current Profile: %1").arg(name));
ui->profileInfoLabel->setText(html); ui->profileInfoLabel->setText(html);
on_diskSpaceInfo_linkActivated(showDiskUsage ? "show" : "hide"); // don't show disk info by default
} else { } else {
ui->diskSpaceInfo->setVisible(false); ui->diskSpaceInfo->setVisible(false);
} } */
} }
@ -314,6 +326,8 @@ void ProfileSelector::on_buttonEditProfile_clicked()
} }
delete newprof; delete newprof;
} else {
QMessageBox::information(this, STR_MessageBox_Information, tr("Select a profile first"), QMessageBox::Ok);
} }
} }
@ -386,7 +400,7 @@ void ProfileSelector::on_buttonDestroyProfile_clicked()
QDialog confirmdlg; QDialog confirmdlg;
QVBoxLayout layout(&confirmdlg); QVBoxLayout layout(&confirmdlg);
QLabel message(QString("<b>"+STR_MessageBox_Warning+":</b> "+tr("You are about to destroy profile '<b>%1</b>'.")+"<br/><br/>"+tr("Think carefully, as this will irretrievably delete the profile along with all <b>backup data</b> stored under<br/>%2.")+"<br/><br/>"+tr("Enter the word <b>DELETE</b> below to confirm.")).arg(name).arg(path), &confirmdlg); QLabel message(QString("<b>"+STR_MessageBox_Warning+":</b> "+tr("You are about to destroy profile '<b>%1</b>'.")+"<br/><br/>"+tr("Think carefully, as this will irretrievably delete the profile along with all <b>backup data</b> stored under<br/>%2.")+"<br/><br/>"+tr("Enter the word <b>DELETE</b> below (exactly as shown) to confirm.")).arg(name).arg(path), &confirmdlg);
layout.insertWidget(0,&message,1); layout.insertWidget(0,&message,1);
QLineEdit lineedit(&confirmdlg); QLineEdit lineedit(&confirmdlg);
layout.insertWidget(1, &lineedit, 1); layout.insertWidget(1, &lineedit, 1);
@ -404,7 +418,7 @@ void ProfileSelector::on_buttonDestroyProfile_clicked()
if (confirmdlg.exec() != QDialog::Accepted) if (confirmdlg.exec() != QDialog::Accepted)
return; return;
if (lineedit.text().compare("DELETE")!=0) { if (lineedit.text().compare(tr("DELETE"))!=0) {
QMessageBox::information(NULL, tr("Sorry"), tr("You need to enter DELETE in capital letters."), QMessageBox::Ok); QMessageBox::information(NULL, tr("Sorry"), tr("You need to enter DELETE in capital letters."), QMessageBox::Ok);
return; return;
} }
@ -444,22 +458,30 @@ QString formatSize(qint64 size) {
} }
QString getProfileDiskInfo(Profile *profile)
{
QString html;
if (profile) {
qint64 sizeSummaries = profile->diskSpaceSummaries();
qint64 sizeEvents = profile->diskSpaceEvents();
qint64 sizeBackups = profile->diskSpaceBackups();
html += "<table>"
"<tr><td align=right>"+QObject::tr("Summaries:")+"</td><td>"+formatSize(sizeSummaries)+"</td></tr>"
"<tr><td align=right>"+QObject::tr("Events:")+"</td><td>"+formatSize(sizeEvents)+"</td></tr>"
"<tr><td align=right>"+QObject::tr("Backups:")+"</td><td>"+formatSize(sizeBackups)+"</td></tr>"
"</table>";
}
return html;
}
void ProfileSelector::on_diskSpaceInfo_linkActivated(const QString &link) void ProfileSelector::on_diskSpaceInfo_linkActivated(const QString &link)
{ {
QString html; QString html;
if (link == "show") { if (link == "show") {
html += "<a href='hide'>"+tr("Hide disk usage information")+"</a>"; html += "<a href='hide'>"+tr("Hide disk usage information")+"</a>"+getProfileDiskInfo(p_profile);
if (p_profile) {
qint64 sizeSummaries = p_profile->diskSpaceSummaries();
qint64 sizeEvents = p_profile->diskSpaceEvents();
qint64 sizeBackups = p_profile->diskSpaceBackups();
html += "<table>"
"<tr><td align=right>"+tr("Summaries:")+"</td><td>"+formatSize(sizeSummaries)+"</td></tr>"
"<tr><td align=right>"+tr("Events:")+"</td><td>"+formatSize(sizeEvents)+"</td></tr>"
"<tr><td align=right>"+tr("Backups:")+"</td><td>"+formatSize(sizeBackups)+"</td></tr></table>";
}
showDiskUsage = true; showDiskUsage = true;
} else { } else {
html += "<a href='show'>"+tr("Show disk usage information")+"</a>"; html += "<a href='show'>"+tr("Show disk usage information")+"</a>";
@ -467,3 +489,43 @@ void ProfileSelector::on_diskSpaceInfo_linkActivated(const QString &link)
} }
ui->diskSpaceInfo->setText(html); ui->diskSpaceInfo->setText(html);
} }
void ProfileSelector::on_selectionChanged(const QModelIndex &index, const QModelIndex &)
{
bool enabled = false;
if (index.isValid()) {
QString name = proxy->data(proxy->index(index.row(), 0, QModelIndex()), Qt::UserRole+2).toString();
auto prof = Profiles::profiles.find(name);
if (prof != Profiles::profiles.end()) {
enabled = true;
QString html = QString();
Profile * profile = prof.value();
if (!profile->user->lastName().isEmpty() && !profile->user->firstName().isEmpty()) {
html += tr("Name: %1, %2").arg(profile->user->lastName()).arg(profile->user->firstName())+"<br/>";
}
if (!profile->user->phone().isEmpty()) {
html += tr("Phone: %1").arg(profile->user->phone())+"<br/>";
}
if (!profile->user->email().isEmpty()) {
html += tr("Email: <a href='mailto:%1'>%1</a>").arg(profile->user->email())+"<br/>";
}
if (!profile->user->address().isEmpty()) {
html += "<br/>"+tr("Address:")+"<br/>"+profile->user->address().trimmed().replace("\n","<br/>")+"<br/>";
}
if (html.isEmpty()) {
html += tr("No profile information given")+"<br/>";
}
ui->diskSpaceInfo->setVisible(true);
ui->profileInfoGroupBox->setTitle(tr("Profile: %1").arg(name));
ui->profileInfoLabel->setText(html);
if (showDiskUsage) { // ugly, but uh....
ui->diskSpaceInfo->setText("<a href='hide'>"+tr("Hide disk usage information")+"</a>"+getProfileDiskInfo(prof.value()));
}
} else {
ui->diskSpaceInfo->setText("Something went wrong");
}
}
ui->buttonEditProfile->setEnabled(enabled);
}

View File

@ -53,6 +53,8 @@ private slots:
void on_diskSpaceInfo_linkActivated(const QString &link); void on_diskSpaceInfo_linkActivated(const QString &link);
void on_selectionChanged(const QModelIndex &current, const QModelIndex &previous);
private: private:
Ui::ProfileSelector *ui; Ui::ProfileSelector *ui;
QStandardItemModel *model; QStandardItemModel *model;

View File

@ -58,7 +58,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::NoSelection</enum>
</property> </property>
<property name="selectionBehavior"> <property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum> <enum>QAbstractItemView::SelectRows</enum>
@ -244,7 +244,7 @@
</font> </font>
</property> </property>
<property name="title"> <property name="title">
<string>Current Profile: None</string> <string>Profile: None</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>