From addeb5563b38edfe3755a78294d773c76024de87 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Mar 2010 23:56:21 +0100 Subject: [PATCH] added himd autodetection function (Windows only) --- qhimdtransfer/qhimddetection.cpp | 489 +++++++++++++++++++++++++++++++++++++ qhimdtransfer/qhimddetection.h | 94 +++++++ qhimdtransfer/qhimddetection.ui | 30 +++ qhimdtransfer/qhimdmainwindow.cpp | 115 +++++++++- qhimdtransfer/qhimdmainwindow.h | 17 ++- qhimdtransfer/qhimdmainwindow.ui | 7 +- qhimdtransfer/qhimdtransfer.pro | 74 ++++--- 7 files changed, 791 insertions(+), 35 deletions(-) create mode 100644 qhimdtransfer/qhimddetection.cpp create mode 100644 qhimdtransfer/qhimddetection.h create mode 100644 qhimdtransfer/qhimddetection.ui diff --git a/qhimdtransfer/qhimddetection.cpp b/qhimdtransfer/qhimddetection.cpp new file mode 100644 index 0000000..fc02cdc --- /dev/null +++ b/qhimdtransfer/qhimddetection.cpp @@ -0,0 +1,489 @@ +#include "qhimddetection.h" +#include "ui_qhimddetection.h" + +#include +#include +#include + +#ifdef Q_OS_WIN + #include + #include + #include // needed to handle GUIDs + #include // needed for handling storage devices + #include // needed for CM_Get_Child function +#endif + +#ifdef Q_OS_WIN + +void QHiMDDetection::autodetect_close() +{ + while (!device_list.isEmpty()) + remove_himddevice(device_list.at(0)->path); + + return; +} + +void QHiMDDetection::scan_for_himd_devices() +{ + unsigned long drives = GetLogicalDrives(); + char drive[] = "A:\\"; + QString name, devID; + + for (; drive[0] <= 'Z'; ++drive[0]) + { + if (drives & 0x1) + { + if(GetDriveTypeA(drive) == DRIVE_REMOVABLE) + { + devID = get_deviceID_from_driveletter(drive[0]); + if(!devID.isEmpty() && !devID.contains("Floppy", Qt::CaseInsensitive)) + { + if(is_himddevice(devID, name)) + add_himddevice(QString(drive[0]) + ":/", name); + } + } + } + drives = drives >> 1; + } + return; +} + +int QHiMDDetection::find_device(HANDLE devhandle, QString path) +{ + int i = 0; + bool found = false; + + if (device_list.isEmpty()) + return -1; + if(!path.isEmpty()) + { + for (; i < device_list.size(); i++) + { + if(device_list.at(i)->path == path) + { + found = true; + break; + } + } + } + else if(devhandle != NULL) + { + for (; i < device_list.size(); i++) + { + if(device_list.at(i)->devhandle == devhandle) + { + found = true; + break; + } + } + } + + if (found) + return i; + + return -1; +} + + +QString QHiMDDetection::get_deviceID_from_driveletter(char i) +{ + char subkey[] = "\\DosDevices\\X:"; + DWORD valuesize; + HKEY key; + int res; + QString devname; + + subkey[12] = i; + res = RegOpenKeyExA( HKEY_LOCAL_MACHINE, "SYSTEM\\MountedDevices", NULL, KEY_QUERY_VALUE, &key); + if(res != ERROR_SUCCESS) + return QString(); + + if(RegQueryValueExA(key, subkey, NULL, NULL, NULL, &valuesize) == ERROR_SUCCESS) + { + char *value = new char[valuesize]; + res = RegQueryValueExA(key, subkey, NULL, NULL,(LPBYTE) value, &valuesize); + if(res == ERROR_SUCCESS) + { + devname = QString::fromUtf16((ushort*)value); + devname.remove(0,4); // modify devname to make a valid device ID + devname.truncate(devname.indexOf("{") -1); + devname = devname.toUpper(); + devname.replace("#", "\\"); + } + delete[] value; + } + RegCloseKey(key); + return devname; +} + +bool QHiMDDetection::is_himddevice(QString devID, QString & name) +{ + DEVINST devinst; + DEVINST devinstparent; + unsigned long buflen; + QString recname, devicepath; + + CM_Locate_DevNodeA(&devinst, devID.toAscii().data(), NULL); + CM_Get_Parent(&devinstparent, devinst, NULL); + + if(devID.contains("RemovableMedia", Qt::CaseInsensitive)) // on Windows XP: get next parent device instance + CM_Get_Parent(&devinstparent, devinstparent, NULL); + + CM_Get_Device_ID_Size(&buflen, devinstparent, 0); + wchar_t *buffer = new wchar_t[buflen]; + CM_Get_Device_ID(devinstparent, buffer, buflen, 0); + devicepath = QString::fromWCharArray(buffer); + delete[] buffer; + + if(identified( devicepath, recname)) + { + name = recname; + return true; + } + return false; +} + +bool QHiMDDetection::identified(QString devpath, QString & name) +{ + int vid = devpath.mid(devpath.indexOf("VID") + 4, 4).toInt(NULL,16); + int pid = devpath.mid(devpath.indexOf("PID") + 4, 4).toInt(NULL,16); + + if (vid != SONY) + return false; + + switch (pid) + { + case MZ_NH1: + name = "SONY MZ-NH1"; + break; + case MZ_NH3D: + name = "SONY MZ-NH3D"; + break; + case MZ_NH900: + name = "SONY MZ-NH900"; + break; + case MZ_NH700: + name = "SONY MZ-NH700 / MZ-NH800"; + break; + case MZ_NH600: + name = "SONY MZ-NH600(D)"; + break; + case LAM_3: + name = "SONY LAM-3"; + break; + case MZ_DH10P: + name = "SONY MZ-DH10P"; + break; + case MZ_RH10: + name = "SONY MZ-RH10"; + break; + case MZ_RH910: + name = "SONY MZ-RH910"; + break; + case CMT_AH10: + name = "SONY CMT-AH10"; + break; + case DS_HMD1: + name = "SONY DS-HMD1"; + break; + case MZ_RH1: + name = "SONY MZ-RH1"; + break; + default: return false; + } + return true; +} + +void QHiMDDetection::add_himddevice(QString path, QString name) +{ + if (find_device(NULL, path) >= 0) + return; + + himd_device * new_device = new himd_device; + int k; + char drv[] = "\\\\.\\X:"; + QByteArray device = "\\\\.\\PHYSICALDRIVE"; + char file[] = "X:\\HI-MD.IND"; + DWORD retbytes; + HANDLE hdev; + STORAGE_DEVICE_NUMBER sdn; + OFSTRUCT OFfile; + + drv[4] = path.at(0).toAscii(); + + hdev = CreateFileA(drv, NULL , FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); + if(hdev == INVALID_HANDLE_VALUE) + return; + + k = DeviceIoControl(hdev, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof(sdn), &retbytes, NULL); + CloseHandle(hdev); + if(k != 0) + device.append(QString::number(sdn.DeviceNumber)); + + new_device->devhandle = CreateFileA(device.data(), NULL , FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); + if(new_device->devhandle == INVALID_HANDLE_VALUE) + return; + + new_device->himdChange = register_mediaChange(new_device->devhandle); + new_device->is_busy = false; + new_device->path = path; + new_device->recorder_name = name; + + settings.setValue(new_device->path, new_device->recorder_name); + + file[0] = path.at(0).toAscii(); + if(OpenFile(file, &OFfile, OF_EXIST) != HFILE_ERROR) + { + new_device->md_inserted = true; + emit himd_found(new_device->path); + qDebug() << "himd device at " + new_device->path + " added (" + new_device->recorder_name + ")"; + } + else + { + qDebug() << "himd device at " + new_device->path + " added (" + new_device->recorder_name + ")" + " ; without MD"; + new_device->md_inserted = false; + } + + device_list.append(new_device); + + return; + +} + +void QHiMDDetection::remove_himddevice(QString path) +{ + int i = find_device(NULL, path); + if (i < 0) + return; + + unregister_mediaChange(device_list.at(i)->himdChange); + + if (device_list.at(i)->devhandle != NULL) + CloseHandle(device_list.at(i)->devhandle); + + if(settings.contains(device_list.at(i)->path)) + settings.remove(device_list.at(i)->path); + emit himd_removed(device_list.at(i)->path); + + qDebug() << "himd device at " + device_list.at(i)->path + " removed (" + device_list.at(i)->recorder_name + ")"; + + delete device_list.at(i); + device_list.removeAt(i); +} + +bool QHiMDDetection::check_removal(HANDLE devhandle, QString & path) +{ + int i = find_device(devhandle, NULL); + if (i < 0) + return false; + + path = device_list.at(i)->path; + return device_list.at(i)->is_busy; +} + +void QHiMDDetection::add_himd(HANDLE devhandle) +{ + int i = find_device(devhandle, NULL); + if (i < 0) + return; + + if(device_list.at(i)->md_inserted != true) + { + device_list.at(i)->md_inserted = true; + emit himd_found(device_list.at(i)->path); + qDebug() << "himd device at " + device_list.at(i)->path + " : md inserted"; + } + return; +} + +void QHiMDDetection::remove_himd(HANDLE devhandle) +{ + int i = find_device(devhandle, NULL); + if (i < 0) + return; + + if(device_list.at(i)->md_inserted != false) + { + device_list.at(i)->md_inserted = false; + emit himd_removed(device_list.at(i)->path); + qDebug() << "himd device at " + device_list.at(i)->path + " : md removed"; + } + return; +} + +HDEVNOTIFY QHiMDDetection::register_mediaChange(HANDLE devhandle) +{ + DEV_BROADCAST_HANDLE filter; + + ZeroMemory( &filter, sizeof(filter) ); + filter.dbch_size = sizeof(DEV_BROADCAST_HANDLE); + filter.dbch_devicetype = DBT_DEVTYP_HANDLE; + filter.dbch_handle = devhandle; + filter.dbch_eventguid = GUID_IO_MEDIA_ARRIVAL; // includes GUID_IO_MEDIA_REMOVAL notification + + return RegisterDeviceNotification( this->winId(), &filter, DEVICE_NOTIFY_WINDOW_HANDLE); + +} + +void QHiMDDetection::unregister_mediaChange(HDEVNOTIFY himd_change) +{ + if(himd_change != NULL) + UnregisterDeviceNotification(himd_change); +} + +bool QHiMDDetection::winEvent(MSG * msg, long * result) + { + QString name, devID, path ; + const int DBT_CUSTOMEVENT = 0x8006; + + if(msg->message == WM_DEVICECHANGE) + { + PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR )msg->lParam; + switch(msg->wParam) + { + case DBT_DEVICEARRIVAL : + { + if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) + { + PDEV_BROADCAST_VOLUME pHdrv = (PDEV_BROADCAST_VOLUME)pHdr; + path = FindPath(pHdrv->dbcv_unitmask); + devID = get_deviceID_from_driveletter(path.at(0).toAscii()); + if(!devID.isEmpty()) + { + if(is_himddevice(devID, name)) + { + qDebug() << "Message:DBT_DEVICEARRIVAL for drive " + path; + add_himddevice(path, name); + } + } + } + break; + } + case DBT_DEVICEREMOVECOMPLETE : + { + if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) + { + PDEV_BROADCAST_VOLUME pHdrv = (PDEV_BROADCAST_VOLUME)pHdr; + path = FindPath(pHdrv->dbcv_unitmask); + qDebug() << "Message:DBT_DEVICEREMOVECOMPLETE for drive " + path; + remove_himddevice(path); + } + break; + } + case DBT_DEVICEQUERYREMOVE : + { + if(pHdr->dbch_devicetype & DBT_DEVTYP_HANDLE) + { + PDEV_BROADCAST_HANDLE pHdrh = (PDEV_BROADCAST_HANDLE)pHdr; + if(check_removal(pHdrh->dbch_handle, path)) + { + *result = BROADCAST_QUERY_DENY; + qDebug() << "Message:DBT_DEVICEQUERYREMOVE for drive " + path + " denied: transfer in progress"; + return true; + } + else + { + qDebug() << "Message:DBT_DEVICEQUERYREMOVE requested"; + remove_himddevice(path); + } + } + break; + } + case DBT_CUSTOMEVENT : + { + if(pHdr->dbch_devicetype & DBT_DEVTYP_HANDLE) + { + PDEV_BROADCAST_HANDLE pHdrh = (PDEV_BROADCAST_HANDLE)pHdr; + if (pHdrh->dbch_eventguid == GUID_IO_MEDIA_ARRIVAL) + { + qDebug() << "Message:DBT_CUSTOMEVENT - GUID_IO_MEDIA_ARRIVAL"; + add_himd(pHdrh->dbch_handle); + break; + } + if (pHdrh->dbch_eventguid == GUID_IO_MEDIA_REMOVAL) + { + qDebug() << "Message:DBT_CUSTOMEVENT - GUID_IO_MEDIA_REMOVAL"; + remove_himd(pHdrh->dbch_handle); + break; + } + } + break; + } + default: return false; // skip unknown/unused messages + } + *result = TRUE; + return true; + } + return false; + } + +QString QHiMDDetection::FindPath (unsigned long unitmask) +{ + char i; + + for (i = 0; i < 26; ++i) + { + if (unitmask & 0x1) + break; + unitmask = unitmask >> 1; + } + return QString(i + 'A') + ":/"; +} + +#endif + +QHiMDDetection::QHiMDDetection(QWidget *parent) : + QDialog(parent), + m_ui(new Ui::QHiMDDetection) +{ + m_ui->setupUi(this); +} + +QHiMDDetection::~QHiMDDetection() +{ + delete m_ui; +} + +void QHiMDDetection::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + m_ui->retranslateUi(this); + break; + default: + break; + } +} + +void QHiMDDetection::closeEvent(QCloseEvent *event) +{ + disconnect(); + autodetect_close(); +} + +// slots + +void QHiMDDetection::on_himd_busy(QString path) +{ + int i = find_device(NULL, path); + if (i < 0) + return; + + device_list.at(i)->is_busy = true; + qDebug() << "himd device at " + device_list.at(i)->path + " : device busy, starting transfer"; +} + +void QHiMDDetection::on_himd_idle(QString path) +{ + int i = find_device(NULL, path); + if (i < 0) + return; + + device_list.at(i)->is_busy = false; + qDebug() << "himd device at " + device_list.at(i)->path + " : device idle, transfer complete"; +} + + diff --git a/qhimdtransfer/qhimddetection.h b/qhimdtransfer/qhimddetection.h new file mode 100644 index 0000000..0892627 --- /dev/null +++ b/qhimdtransfer/qhimddetection.h @@ -0,0 +1,94 @@ +#ifndef QHIMDDETECTION_H +#define QHIMDDETECTION_H + +#include +#include +#include + +#ifdef Q_OS_WIN + #define WINVER 0x0500 + #include +#endif + +#define SONY 0x054c //known himd-mode product IDs +#define MZ_NH1 0x017f +#define MZ_NH3D 0x0181 +#define MZ_NH900 0x0183 +#define MZ_NH700 0x0185 +#define MZ_NH600 0x0187 +#define LAM_3 0x018a +#define MZ_DH10P 0x01ea +#define MZ_RH10 0x021a +#define MZ_RH910 0x021c +#define CMT_AH10 0x022d +#define DS_HMD1 0x023d +#define MZ_RH1 0x0287 + +struct himd_device { //information for each found himd device + bool is_busy; + HANDLE devhandle; + HDEVNOTIFY himdChange; + QString path; + bool md_inserted; + QString recorder_name; + }; + +static const GUID GUID_IO_MEDIA_ARRIVAL = + {0xd07433c0, 0xa98e, 0x11d2, {0x91, 0x7a, 0x00, 0xa0, 0xc9, 0x06, 0x8f, 0xf3} }; + +static const GUID GUID_IO_MEDIA_REMOVAL = + {0xd07433c1, 0xa98e, 0x11d2, {0x91, 0x7a, 0x00, 0xa0, 0xc9, 0x06, 0x8f, 0xf3} }; + +static const GUID GUID_DEVINTERFACE_USB_DEVICE = + {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed} }; + +namespace Ui { + class QHiMDDetection; +} + +class QHiMDDetection : public QDialog { + Q_OBJECT + Q_DISABLE_COPY(QHiMDDetection) +public: + explicit QHiMDDetection(QWidget *parent = 0); + virtual ~QHiMDDetection(); + #ifdef Q_OS_WIN + void autodetect_close(); + void scan_for_himd_devices(); + #endif + +protected: + virtual void changeEvent(QEvent *e); + virtual void closeEvent(QCloseEvent *event); + +private: + Ui::QHiMDDetection *m_ui; + QSettings settings; + #ifdef Q_OS_WIN + HDEVNOTIFY hDevNotify; + QList device_list; + int find_device(HANDLE devhandle, QString path); + QString get_deviceID_from_driveletter(char i); + bool is_himddevice(QString devID, QString & name); + bool identified(QString devpath, QString & name); + void add_himddevice(QString path, QString name); + void remove_himddevice(QString path); + bool check_removal(HANDLE devhandle, QString & path); + void add_himd(HANDLE devhandle); + void remove_himd(HANDLE devhandle); + HDEVNOTIFY register_mediaChange(HANDLE devhandle); + void unregister_mediaChange(HDEVNOTIFY himd_change); + bool winEvent(MSG * msg, long * result); + QString FindPath(unsigned long unitmask); + #endif + +private slots: + void on_himd_busy(QString path); + void on_himd_idle(QString path); + +signals: + void himd_found(QString path); + void himd_removed(QString path); +}; + +#endif // QHIMDDETECTION_H diff --git a/qhimdtransfer/qhimddetection.ui b/qhimdtransfer/qhimddetection.ui new file mode 100644 index 0000000..32e49b5 --- /dev/null +++ b/qhimdtransfer/qhimddetection.ui @@ -0,0 +1,30 @@ + + + QHiMDDetection + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 9 + 9 + 381 + 281 + + + + + + + + diff --git a/qhimdtransfer/qhimdmainwindow.cpp b/qhimdtransfer/qhimdmainwindow.cpp index 78a1786..8d6949d 100644 --- a/qhimdtransfer/qhimdmainwindow.cpp +++ b/qhimdtransfer/qhimdmainwindow.cpp @@ -239,7 +239,9 @@ void QHiMDMainWindow::init_local_browser() QStringList DownloadFileList; localmodel.setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); localmodel.setNameFilters(QStringList() << "*.mp3" << "*.wav" << "*.oma"); - localmodel.setSorting(QDir::DirsFirst | QDir::Name); + localmodel.setNameFilterDisables(false); + localmodel.setReadOnly(false); + localmodel.setRootPath("/home"); ui->localScan->setModel(&localmodel); QModelIndex curdir = localmodel.index(ui->updir->text()); ui->localScan->expand(curdir); @@ -250,6 +252,24 @@ void QHiMDMainWindow::init_local_browser() ui->localScan->setColumnWidth(0, 350); } +bool QHiMDMainWindow::autodetect_init() +{ + int k; + + k = QObject::connect(detect, SIGNAL(himd_found(QString)), this, SLOT(on_himd_found(QString))); + k += QObject::connect(detect, SIGNAL(himd_removed(QString)), this, SLOT(on_himd_removed(QString))); + + if(!k) + return false; + + QObject::connect(this, SIGNAL(himd_busy(QString)), detect, SLOT(on_himd_busy(QString))); + QObject::connect(this, SIGNAL(himd_idle(QString)), detect, SLOT(on_himd_idle(QString))); + + detect->scan_for_himd_devices(); + return true; +} + + void QHiMDMainWindow::open_himd_at(const QString & path) { QMessageBox himdStatus; @@ -267,11 +287,18 @@ void QHiMDMainWindow::open_himd_at(const QString & path) ui->himdpath->setText(path); settings.setValue("lastHiMDDirectory", path); + if(settings.contains(path)) + ui->statusBar->showMessage(settings.value(path, QString()).toString()); + else + ui->statusBar->clearMessage(); + set_buttons_enable(1,0,0,1,1,1,1); } void QHiMDMainWindow::upload_to(const QString & UploadDirectory) { + emit himd_busy(ui->himdpath->text()); + QHiMDTrackList tracks = trackmodel.tracks(ui->TrackList->selectionModel()->selectedRows(0)); int allblocks = 0; @@ -324,7 +351,8 @@ void QHiMDMainWindow::upload_to(const QString & UploadDirectory) break; } uploadDialog->finished(); - localmodel.refresh(); + + emit himd_idle(ui->himdpath->text()); } QHiMDMainWindow::QHiMDMainWindow(QWidget *parent) @@ -333,12 +361,18 @@ QHiMDMainWindow::QHiMDMainWindow(QWidget *parent) aboutDialog = new QHiMDAboutDialog; formatDialog = new QHiMDFormatDialog; uploadDialog = new QHiMDUploadDialog; + detect = new QHiMDDetection; ui->setupUi(this); ui->updir->setText(settings.value("lastUploadDirectory", QDir::homePath()).toString()); set_buttons_enable(1,0,0,0,0,0,1); init_himd_browser(); init_local_browser(); + ui->himd_devices->hide(); + #ifdef Q_OS_WIN + if(!autodetect_init()) + ui->statusBar->showMessage(" autodetection disabled", 10000); + #endif } QHiMDMainWindow::~QHiMDMainWindow() @@ -393,6 +427,7 @@ void QHiMDMainWindow::on_action_Format_triggered() void QHiMDMainWindow::on_action_Connect_triggered() { + int index; QString HiMDDirectory; HiMDDirectory = settings.value("lastHiMDDirectory", QDir::rootPath()).toString(); HiMDDirectory = QFileDialog::getExistingDirectory(this, @@ -403,6 +438,20 @@ void QHiMDMainWindow::on_action_Connect_triggered() if(HiMDDirectory.isEmpty()) return; + index = ui->himd_devices->findText(HiMDDirectory); + if(index == -1) + { + ui->himd_devices->addItem(HiMDDirectory); + index = ui->himd_devices->findText(HiMDDirectory); + } + ui->himd_devices->setCurrentIndex(index); + + if(ui->himd_devices->isHidden()) + { + ui->himd_devices->show(); + ui->himdpath->hide(); + } + open_himd_at(HiMDDirectory); } @@ -426,3 +475,65 @@ void QHiMDMainWindow::handle_selection_change(const QItemSelection&, const QItem ui->action_Upload->setEnabled(nonempty); ui->upload_button->setEnabled(nonempty); } + +void QHiMDMainWindow::on_himd_found(QString HiMDPath) +{ + int index; + + if(HiMDPath.isEmpty()) + return; + + index = ui->himd_devices->findText(HiMDPath); + if(index == -1) + ui->himd_devices->addItem(HiMDPath); + + if(ui->himd_devices->isHidden()) + { + ui->himd_devices->show(); + ui->himdpath->hide(); + } + + if(ui->himdpath->text() == "(disconnected)") + { + index = ui->himd_devices->findText(HiMDPath); + ui->himd_devices->setCurrentIndex(index); + open_himd_at(HiMDPath); + } + +} + +void QHiMDMainWindow::on_himd_removed(QString HiMDPath) +{ + int index; + + if(HiMDPath.isEmpty()) + return; + if (ui->himdpath->text() == HiMDPath) + { + ui->himdpath->setText("(disconnected)"); + ui->statusBar->clearMessage(); + trackmodel.close(); + } + + index = ui->himd_devices->findText(HiMDPath); + if(index != -1) + { + ui->himd_devices->removeItem(index); + } + + if(ui->himd_devices->count() == 0) + { + ui->himd_devices->hide(); + ui->himdpath->show(); + } +} + +void QHiMDMainWindow::on_himd_devices_activated(QString device) +{ + open_himd_at(device); +} + +void QHiMDMainWindow::closeEvent(QCloseEvent *event) +{ + detect->close(); +} diff --git a/qhimdtransfer/qhimdmainwindow.h b/qhimdtransfer/qhimdmainwindow.h index 9bc9fc1..22b9772 100644 --- a/qhimdtransfer/qhimdmainwindow.h +++ b/qhimdtransfer/qhimdmainwindow.h @@ -4,10 +4,11 @@ #include #include #include -#include +#include #include "qhimdaboutdialog.h" #include "qhimdformatdialog.h" #include "qhimduploaddialog.h" +#include "qhimddetection.h" #include "qhimdmodel.h" #include "../libhimd/himd.h" #include @@ -37,8 +38,9 @@ private: QHiMDAboutDialog * aboutDialog; QHiMDFormatDialog * formatDialog; QHiMDUploadDialog * uploadDialog; + QHiMDDetection * detect; QHiMDTracksModel trackmodel; - QDirModel localmodel; + QFileSystemModel localmodel; QSettings settings; QString dumpmp3(const QHiMDTrack & trk, QString file); QString dumpoma(const QHiMDTrack & trk, QString file); @@ -47,9 +49,13 @@ private: void set_buttons_enable(bool connect, bool download, bool upload, bool rename, bool del, bool format, bool quit); void init_himd_browser(); void init_local_browser(); + bool autodetect_init(); void open_himd_at(const QString & path); void upload_to(const QString & path); +protected: + void closeEvent(QCloseEvent *event); + private slots: void on_action_Connect_triggered(); void on_action_Format_triggered(); @@ -60,6 +66,13 @@ private slots: void on_localScan_clicked(QModelIndex index); void on_upload_button_clicked(); void handle_selection_change(const QItemSelection&, const QItemSelection&); + void on_himd_found(QString path); + void on_himd_removed(QString path); + void on_himd_devices_activated(QString device); + +signals: + void himd_busy(QString path); + void himd_idle(QString path); }; #endif // QHIMDMAINWINDOW_H diff --git a/qhimdtransfer/qhimdmainwindow.ui b/qhimdtransfer/qhimdmainwindow.ui index 65f7483..149bd77 100644 --- a/qhimdtransfer/qhimdmainwindow.ui +++ b/qhimdtransfer/qhimdmainwindow.ui @@ -25,7 +25,7 @@ - + @@ -46,6 +46,9 @@ + + + @@ -165,7 +168,7 @@ 0 0 784 - 24 + 18 diff --git a/qhimdtransfer/qhimdtransfer.pro b/qhimdtransfer/qhimdtransfer.pro index 8cbe2b2..aac0e2a 100644 --- a/qhimdtransfer/qhimdtransfer.pro +++ b/qhimdtransfer/qhimdtransfer.pro @@ -1,5 +1,6 @@ TEMPLATE = app -CONFIG += link_prl link_pkgconfig +CONFIG += link_prl \ + link_pkgconfig TARGET = qhimdtransfer DEPENDPATH += . INCLUDEPATH += . @@ -7,46 +8,61 @@ INCLUDEPATH += . # language logic heavily inspired by Qt Creator's # share/qtcreator/translations/translations.pro include(translate.pri) -LANGUAGES = de nb sv fr pt pl ru it ja fi ar el +LANGUAGES = de \ + nb \ + sv \ + fr \ + pt \ + pl \ + ru \ + it \ + ja \ + fi \ + ar \ + el TRANSLATIONS = $$bracketAll(LANGUAGES, $$PWD/qhimdtransfer_,.ts) # Input - HEADERS += qhimdaboutdialog.h \ - qhimdformatdialog.h \ - qhimduploaddialog.h \ - qhimdmainwindow.h \ - qhimdmodel.h -FORMS += qhimdaboutdialog.ui qhimdformatdialog.ui qhimduploaddialog.ui qhimdmainwindow.ui + qhimdformatdialog.h \ + qhimduploaddialog.h \ + qhimdmainwindow.h \ + qhimdmodel.h +win32:HEADERS += qhimddetection.h +FORMS += qhimdaboutdialog.ui \ + qhimdformatdialog.ui \ + qhimduploaddialog.ui \ + qhimdmainwindow.ui +win32:FORMS += qhimddetection.ui SOURCES += main.cpp \ - qhimdaboutdialog.cpp \ - qhimdformatdialog.cpp \ - qhimduploaddialog.cpp \ - qhimdmainwindow.cpp \ - qhimdmodel.cpp + qhimdaboutdialog.cpp \ + qhimdformatdialog.cpp \ + qhimduploaddialog.cpp \ + qhimdmainwindow.cpp \ + qhimdmodel.cpp +win32:SOURCES += qhimddetection.cpp RESOURCES += icons.qrc -PKGCONFIG += sox taglib -win32: RC_FILE = qhimdtransfer.rc -mac: ICON = qhimdtransfer.icns +PKGCONFIG += sox \ + taglib +win32:LIBS += -lsetupapi -lcfgmgr32 +win32:RC_FILE = qhimdtransfer.rc +mac:ICON = qhimdtransfer.icns # Mixed case version of the target name for operating systems on which # this is convention. -win32: TARGET=QHiMDTransfer -mac: TARGET=QHiMDTransfer - +win32:TARGET = QHiMDTransfer +mac:TARGET = QHiMDTransfer include(../libhimd/use_libhimd.pri) # Installing stuff - translations.files = $$bracketAll(LANGUAGES, $$OUT_PWD/qhimdtransfer_,.qm) - -unix: !macx { - target.path = /usr/bin - translations.path = /usr/share/qhimdtransfer/translations - INSTALLS += target translations +unix:!macx { + target.path = /usr/bin + translations.path = /usr/share/qhimdtransfer/translations + INSTALLS += target \ + translations } - -macx { - translations.path = myapp.app/Contents/Resources/translations - INSTALLS += translations +macx { + translations.path = myapp.app/Contents/Resources/translations + INSTALLS += translations } -- 1.6.4.msysgit.0