New Feature: Added Import locations preference tab and related import logic

This commit is contained in:
Mark Watkins 2011-11-21 09:39:55 +10:00
parent 3e64de984e
commit 4d41fcf997
6 changed files with 231 additions and 29 deletions

View File

@ -4,6 +4,10 @@ SleepLib (DeVilbiss) Intellipap Loader Implementation
Author: Mark Watkins <jedimark64@users.sourceforge.net>
License: GPL
Notes: Intellipap requires the SmartLink attachment to access this data.
It does not seem to record multiple days, graph data is overwritten each time..
*/
#include "intellipap_loader.h"
@ -22,14 +26,20 @@ Intellipap::~Intellipap()
IntellipapLoader::IntellipapLoader()
{
m_buffer=NULL;
}
IntellipapLoader::~IntellipapLoader()
{
for (QHash<QString,Machine *>::iterator i=MachList.begin(); i!=MachList.end(); i++) {
delete i.value();
}
}
int IntellipapLoader::Open(QString & path,Profile *profile)
{
// Check for DV5MFirm.bin
return 0;
}

View File

@ -18,10 +18,13 @@
#include "SleepLib/profiles.h"
#include "profileselect.h"
#include "newprofile.h"
// Gah! I must add the real darn plugin system one day.
#include "SleepLib/loader_plugins/prs1_loader.h"
#include "SleepLib/loader_plugins/cms50_loader.h"
#include "SleepLib/loader_plugins/zeo_loader.h"
#include "SleepLib/loader_plugins/resmed_loader.h"
#include "SleepLib/loader_plugins/intellipap_loader.h"
#ifdef Q_WS_X11
#include <X11/Xlib.h>
@ -94,6 +97,7 @@ int main(int argc, char *argv[])
CMS50Loader::Register();
ZEOLoader::Register();
ResmedLoader::Register();
IntellipapLoader::Register();
Profiles::Scan();
PREF["AppName"]="SleepyHead";
bool skip_login=(PREF.ExistsAndTrue("SkipLoginScreen"));

View File

@ -212,40 +212,86 @@ void MainWindow::Startup()
void MainWindow::on_action_Import_Data_triggered()
{
//QStringList dirNames;
QStringList importLocations;
{
QString filename=PROFILE.Get("{DataFolder}/ImportLocations.txt");
QFile file(filename);
file.open(QFile::ReadOnly);
QTextStream textStream(&file);
while (1) {
QString line = textStream.readLine();
if (line.isNull())
break;
else if (line.isEmpty())
continue;
else {
importLocations.append(line);
}
};
file.close();
}
//QFileDialog qfd(this);
//qfd.setFileMode(QFileDialog::Directory);
//qfd.setOption(QFileDialog::ShowDirsOnly,true);
QString dir=QFileDialog::getExistingDirectory(this,"Select a folder to import","",QFileDialog::ShowDirsOnly);
bool addnew=false;
QString newdir;
bool asknew=false;
if (importLocations.size()==0) {
asknew=true;
} else {
int res=QMessageBox::question(this,"Import from where?","Do you just want to Import from the usual (remembered) locations?\n","The Usual","New Location","Cancel",0,2);
if (res==1) {
asknew=true;
}
if (res==2) return;
}
if (asknew) {
newdir=QFileDialog::getExistingDirectory(this,"Select a folder to import","",QFileDialog::ShowDirsOnly);
if (newdir.isEmpty()) {
// inform the user or just abort?
return;
}
if (!importLocations.contains(newdir)) {
importLocations.append(newdir);
addnew=true;
}
}
int successful=false;
for (int i=0;i<importLocations.size();i++) {
QString dir=importLocations[i];
if (!dir.isEmpty()) {
//if (qfd.exec()) {
qprogress->setValue(0);
qprogress->show();
qstatus->setText(tr("Importing Data"));
int c=PROFILE.Import(dir);
if (!c) {
QMessageBox::warning(this,"Import Problem","Couldn't Find any Machine Data at this location:\n"+dir,QMessageBox::Ok);
if (newdir==dir) addnew=false; // Don't bother asking to add it.
}
/*dirNames=qfd.selectedFiles();
int c=0,d;
for (int i=0;i<dirNames.size();i++) {
d=profile->Import(dirNames[i]);
if (!d) {
QMessageBox::warning(this,"Import Problem","Couldn't Find any Machine Data at this location:\n"+dirNames[i],QMessageBox::Ok);
}
c+=d;
}*/
qDebug() << "Finished Importing data" << c;
if (c) {
PROFILE.Save();
if (daily) daily->ReloadGraphs();
if (overview) overview->ReloadGraphs();
successful=true;
}
qstatus->setText("");
qprogress->hide();
}
}
if (successful) {
PROFILE.Save();
if (daily) daily->ReloadGraphs();
if (overview) overview->ReloadGraphs();
if (addnew && (QMessageBox::question(this,"Remember this Location?","Would you like to remember this import location for next time?\n"+newdir,QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)) {
QString filename=PROFILE.Get("{DataFolder}/ImportLocations.txt");
QFile file(filename);
file.open(QFile::WriteOnly);
QTextStream ts(&file);
for (int i=0;i<importLocations.size();i++) {
ts << importLocations[i] << endl;
//file.write(importLocations[i].toUtf8());
}
file.close();
}
}
}
QMenu * MainWindow::CreateMenu(QString title)

View File

@ -4,6 +4,8 @@
#include <QStatusBar>
#include <QProcess>
#include <QDesktopServices>
#include <QFileDialog>
#include <QTextStream>
#include "preferencesdialog.h"
#include "ui_preferencesdialog.h"
#include "SleepLib/machine_common.h"
@ -19,6 +21,25 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) :
{
ui->setupUi(this);
{
QString filename=PROFILE.Get("{DataFolder}/ImportLocations.txt");
QFile file(filename);
file.open(QFile::ReadOnly);
QTextStream textStream(&file);
while (1) {
QString line = textStream.readLine();
if (line.isNull())
break;
else if (line.isEmpty())
continue;
else {
importLocations.append(line);
}
};
file.close();
}
importModel=new QStringListModel(importLocations,this);
ui->importListWidget->setModel(importModel);
ui->tabWidget->removeTab(3);
Q_ASSERT(profile!=NULL);
@ -281,6 +302,18 @@ void PreferencesDialog::Save()
//qDebug() << "TODO: Save channels.xml to update channel data";
{
QString filename=PROFILE.Get("{DataFolder}/ImportLocations.txt");
QFile file(filename);
file.open(QFile::WriteOnly);
QTextStream ts(&file);
for (int i=0;i<importLocations.size();i++) {
ts << importLocations[i] << endl;
//file.write(importLocations[i].toUtf8());
}
file.close();
}
profile->Save();
PREF.Save();
@ -354,3 +387,24 @@ void PreferencesDialog::on_checkForUpdatesButton_clicked()
ui->updateLastChecked->setText("Checking for Updates");
mainwin->CheckForUpdates();
}
void PreferencesDialog::on_addImportLocation_clicked()
{
QString dir=QFileDialog::getExistingDirectory(this,"Add this Location to the Import List","",QFileDialog::ShowDirsOnly);
if (!dir.isEmpty()) {
if (!importLocations.contains(dir)) {
importLocations.append(dir);
importModel->setStringList(importLocations);
}
}
}
void PreferencesDialog::on_removeImportLocation_clicked()
{
if (ui->importListWidget->currentIndex().isValid()) {
QString dir=ui->importListWidget->currentIndex().data().toString();
importModel->removeRow(ui->importListWidget->currentIndex().row());
importLocations.removeAll(dir);
}
}

View File

@ -9,6 +9,7 @@
#include <QDialog>
#include <QModelIndex>
#include <QStringListModel>
#include "SleepLib/profiles.h"
namespace Ui {
@ -34,10 +35,17 @@ private slots:
void on_checkForUpdatesButton_clicked();
void on_addImportLocation_clicked();
void on_removeImportLocation_clicked();
private:
Ui::PreferencesDialog *ui;
Profile * profile;
QHash<int,QColor> m_new_colors;
QStringList importLocations;
QStringListModel *importModel;
};
#endif // PREFERENCESDIALOG_H

View File

@ -1226,6 +1226,86 @@ It has no effect on single cpu machines.</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="importTab">
<attribute name="title">
<string>Import</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_11">
<property name="spacing">
<number>4</number>
</property>
<property name="margin">
<number>4</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Automatically scan these locations during import.</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListView" name="importListWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QPushButton" name="addImportLocation">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeImportLocation">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
<zorder>removeImportLocation</zorder>
<zorder>addImportLocation</zorder>
<zorder>verticalSpacer_5</zorder>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>