From c5696dbe5d8de1f0f3d9d984fdcdec25801709dc Mon Sep 17 00:00:00 2001 From: tiantian Date: Thu, 8 Jun 2023 18:09:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=BB=E7=BA=BF0.19?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MacroFile.h | 2 +- src/UnionVariable.cpp | 1 + src/basewidget.cpp | 6 + src/fdclickwidget.cpp | 3 +- src/fdclickwidget.h | 1 - src/fdframe.cpp | 31 +++-- src/fdframe.h | 3 +- src/flashdiskdata.cpp | 46 ++++--- src/flashdiskdata.h | 9 +- src/interactivedialog.cpp | 2 +- src/mainwindow.cpp | 245 +++++++++++++++++++++++--------------- src/mainwindow.h | 4 +- src/qclickwidget.cpp | 8 +- 13 files changed, 223 insertions(+), 138 deletions(-) diff --git a/src/MacroFile.h b/src/MacroFile.h index fe755b8..5d2f109 100644 --- a/src/MacroFile.h +++ b/src/MacroFile.h @@ -37,7 +37,7 @@ typedef enum {downPosition = 0,upPosition,leftPosition,rightPosition}Suit; #define FLASHDISKITEM_CONTENT_HEIGHT 45 #define FLASHDISKITEM_HEIGHT 112 #define FLASHDISKITEM_SPACE_HEIGHT 7 -#define FLASHDISKITEM_SHOWDISK_MAX 10 +#define FLASHDISKITEM_SHOWDISK_MAX 8 #define NEWINFO_DELAYSHOW_TIME 1500 diff --git a/src/UnionVariable.cpp b/src/UnionVariable.cpp index bbb306a..e616f0c 100644 --- a/src/UnionVariable.cpp +++ b/src/UnionVariable.cpp @@ -199,6 +199,7 @@ QString transcodeForGbkCode(QByteArray gbkName, QString &volumeName) return name; } +//判断是否是当前用户的挂载 bool ifLocalUsrDev(QString mountUri) { QString usrName = qgetenv("USER"); diff --git a/src/basewidget.cpp b/src/basewidget.cpp index 1fec377..18e7117 100644 --- a/src/basewidget.cpp +++ b/src/basewidget.cpp @@ -135,6 +135,9 @@ bool baseWidget::eventFilter(QObject *watched, QEvent *event) { if(event->type() == QEvent::Enter) { qDebug()<<"鼠标进入"; + if(m_hideTimer->isActive()) { + m_hideTimer->stop(); + } return false; } else if (event->type() == QEvent::WindowDeactivate) { @@ -142,6 +145,9 @@ bool baseWidget::eventFilter(QObject *watched, QEvent *event) qDebug()<<"激活外部窗口"; this->hide(); return false; + } else if (event->type() == QEvent::Leave) { + if(m_hideTimer->isActive()) + m_hideTimer->start(2000); } } diff --git a/src/fdclickwidget.cpp b/src/fdclickwidget.cpp index d2da136..0c560e2 100644 --- a/src/fdclickwidget.cpp +++ b/src/fdclickwidget.cpp @@ -68,7 +68,6 @@ FDClickWidget::FDClickWidget(FDFrame *parent, initFontSize(); initThemeMode(); - m_hideTime = new QTimer(this); QHBoxLayout *drivename_H_BoxLayout = new QHBoxLayout(); if (m_uDiskNo <= 1) { image_show_label = new QLabel(this); @@ -215,7 +214,7 @@ FDClickWidget::FDClickWidget(FDFrame *parent, //this->setStyleSheet("border:1px solid red;");//for test connect(this, &FDClickWidget::themeFontChange, this, &FDClickWidget::onThemeFontChange); - connect(m_hideTime, SIGNAL(timeout()), this,SLOT(on_hideinterface())); + //connect(m_hideTime, SIGNAL(timeout()), this,SLOT(on_hideinterface())); //弹出按钮滑动效果 connect(this, &FDClickWidget::hoverEjectBotton, m_frame, &FDFrame::on_updateSize); connect(this, &FDClickWidget::leaveEjectBotton, m_frame, &FDFrame::on_cursorLeave); diff --git a/src/fdclickwidget.h b/src/fdclickwidget.h index 1ea0aa2..3a77c05 100644 --- a/src/fdclickwidget.h +++ b/src/fdclickwidget.h @@ -92,7 +92,6 @@ private: QLabel *m_driveName_label; ClickLabel *m_nameDis1_label; QLabel *m_capacityDis1_label; - QTimer *m_hideTime; QWidget *disWidgetNumOne; QVBoxLayout *main_V_BoxLayout = nullptr; bool m_mousePressFlag = false; diff --git a/src/fdframe.cpp b/src/fdframe.cpp index 1668914..072fbae 100644 --- a/src/fdframe.cpp +++ b/src/fdframe.cpp @@ -35,6 +35,7 @@ #include "config/xatom-helper.h" #include "fdframe.h" +#include "UnionVariable.h" #define THEME_UKFD_TRANS "org.ukui.control-center.personalise" #define IN_THEME_BLACKLIST 0 @@ -62,7 +63,8 @@ FDFrame::FDFrame(QWidget* parent) : QFrame(parent) m_animLabel->show(); m_ejectLabel = new QLabel(this); - m_ejectLabel->setText(tr("eject")); + QString DriveName = getElidedText(m_ejectLabel->font(), tr("eject"), 47); + m_ejectLabel->setText(DriveName); m_ejectLabel->setStyleSheet("QLabel{color: palette(Text);}"); m_ejectLabel->setParent(this); m_ejectLabel->move(328,35); @@ -79,8 +81,8 @@ FDFrame::FDFrame(QWidget* parent) : QFrame(parent) m_ejectIcon->setFixedSize(16,16); m_ejectIcon->show(); - m_hideFrameTime = new QTimer(this); - connect(m_hideFrameTime, SIGNAL(timeout()), this,SLOT(on_hideframe())); +// m_hideFrameTime = new QTimer(this); +// connect(m_hideFrameTime, SIGNAL(timeout()), this,SLOT(on_hideframe())); KWindowEffects::enableBlurBehind(winId(), true); kdk::UkuiStyleHelper::self()->removeHeader(this); } @@ -131,7 +133,7 @@ int FDFrame::readlabeltWidth() void FDFrame::setlabeltWidth(int width) { this->m_animLabel->setFixedWidth(width); - m_ejectIcon->move(width+23,47); + m_ejectIcon->move(width+23,m_mainWindowHigh/2-11); if(width == 288) { m_ejectIcon->setStyleSheet("QLabel{color: palette(Text);}"); @@ -245,9 +247,9 @@ bool FDFrame::eventFilter(QObject *obj, QEvent *event) repaint(); - if (m_hideFrameTime->isActive()) { - m_hideFrameTime->stop(); - } +// if (m_hideFrameTime->isActive()) { +// m_hideFrameTime->stop(); +// } return true; } return false; @@ -283,9 +285,18 @@ void FDFrame::showNoIcon(){ this->show(); } -void FDFrame::on_hideframe() +void FDFrame::setEjectOnCentra(int height) { - //m_hideFrameTime->stop(); - //this->hide(); + + m_ejectIcon->move(343,height/2-11); + m_ejectLabel->move(328,height/2-22); //减去字体高度 + } + +//void FDFrame::on_hideframe() +//{ +// //m_hideFrameTime->stop(); +// //this->hide(); + +//} diff --git a/src/fdframe.h b/src/fdframe.h index 272668d..d16bcb1 100644 --- a/src/fdframe.h +++ b/src/fdframe.h @@ -42,6 +42,7 @@ public: void initOpacityGSettings(); void showNoIcon(); + void setEjectOnCentra(int height); protected: @@ -71,7 +72,7 @@ private: public Q_SLOTS: void on_updateSize(); void on_cursorLeave(); - void on_hideframe(); + //void on_hideframe(); }; #endif diff --git a/src/flashdiskdata.cpp b/src/flashdiskdata.cpp index 2c09427..0340ec8 100644 --- a/src/flashdiskdata.cpp +++ b/src/flashdiskdata.cpp @@ -101,6 +101,7 @@ int FlashDiskData::addVolumeInfoWithDrive(FDDriveInfo driveInfo, FDVolumeInfo vo } map::iterator itDriveInfo = m_devInfoWithDrive.find(driveInfo.strId); if (itDriveInfo != m_devInfoWithDrive.end()) { + itDriveInfo->second.lluVolSum = driveInfo.lluVolSum; itDriveInfo->second.listVolumes[volumeInfo.strId] = volumeInfo; } else { driveInfo.listVolumes.clear(); @@ -193,10 +194,13 @@ int FlashDiskData::removeDriveInfo(FDDriveInfo driveInfo) if (m_devInfoWithDrive.find(driveInfo.strId) != m_devInfoWithDrive.end()) { map::iterator itDriveInfo = m_devInfoWithDrive.find(driveInfo.strId); map::iterator itVolumeInfo = itDriveInfo->second.listVolumes.begin(); - qInfo()<<"m_devInfoWithVolume.size()"<second.mountInfo.strId); - QString mountId = QString::fromStdString(itVolumeInfo->second.mountInfo.strId); - if(!mountId.isEmpty()){ - emitRemoveNotify(mountId,QString::fromStdString(driveInfo.strId)); + + if(!itDriveInfo->second.listVolumes.empty() && !itVolumeInfo->second.mountInfo.lluTotalSize == 0 && !g_str_has_prefix (driveInfo.strId.c_str(), "/dev/sr")){ + string mountId = itVolumeInfo->second.mountInfo.strId; + emitRemoveNotify(QString::fromStdString(mountId),QString::fromStdString(driveInfo.strId)); + } + if((g_str_has_prefix (driveInfo.strId.c_str(), "/dev/sr"))){ + Q_EMIT notifyDeviceRemoved(QString::fromStdString(driveInfo.strId)); } // if(((itDriveInfo->second.islocalUsr == true)||(g_str_has_prefix (driveInfo.strId.c_str(), "/dev/sr")))&&(getAttachedVolumeCount(driveInfo.strId) > 0)){ // //Q_EMIT notifyDeviceRemoved(QString::fromStdString(driveInfo.strId)); @@ -210,6 +214,7 @@ int FlashDiskData::removeDriveInfo(FDDriveInfo driveInfo) int FlashDiskData::removeVolumeInfo(FDVolumeInfo volumeInfo) { + if (volumeInfo.strId.empty()) { return -1; } @@ -262,6 +267,9 @@ int FlashDiskData::removeMountInfo(FDMountInfo mountInfo) // if (ifLocalUsrDev(QString::fromStdString(mountInfo.strId.c_str()))&&getAttachedVolumeCount(itVolumeInfo->second.strId) == 1) { // //Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId)); // } + Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId)); + if((g_str_has_prefix (itVolumeInfo->second.strId.c_str(), "/dev/sr"))) + emitRemoveNotify(QString::fromStdString(mountInfo.strId),QString::fromStdString(itVolumeInfo->second.strId)); //m_devInfoWithVolume.erase(itVolumeInfo); itVolumeInfo->second.mountInfo.strId = ""; #endif @@ -284,11 +292,13 @@ int FlashDiskData::removeMountInfo(FDMountInfo mountInfo) // qInfo()<<"非本用户啊"; // itDriveInfo->second.islocalUsr = false; // } -// qInfo()<<"iflocal:"<second.strId); + qInfo()<<"mountInfo.strId:"<second.strId)); // if (ifLocalUsrDev(QString::fromStdString(mountInfo.strId.c_str()))&&getAttachedVolumeCount(itVolumeInfo->second.strId) == 1) { -// //Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId)); +// Q_EMIT notifyDeviceRemoved(QString::fromStdString(itVolumeInfo->second.strId)); // } -// //itDriveInfo->second.listVolumes.erase(itVolumeInfo); +// itDriveInfo->second.listVolumes.erase(itVolumeInfo); itVolumeInfo->second.mountInfo.strId = ""; #endif return 0; @@ -302,19 +312,20 @@ int FlashDiskData::removeMountInfo(FDMountInfo mountInfo) void FlashDiskData::emitRemoveNotify(QString strmountId, QString strVolumeId) { string strStdVolId = strVolumeId.toStdString(); - qInfo()<<"mountid "< listVolumes; string strIconPath = ""; }FDDriveInfo; @@ -93,24 +94,24 @@ public: void emitRemoveNotify(QString strMountId,QString strVolumeId); unsigned getValidInfoCount(); void clearAllData(); - void setClickToEject(); + void setClickToEject(); + bool getIfClickToEject(); bool isMountInfoExist(FDMountInfo mountInfo); void resetAllNewState(); quint64 getMountTickDiff(FDMountInfo mountInfo); bool getVolumeInfoByMount(FDMountInfo mountInfo, FDVolumeInfo& volumeInfo); unsigned getAttachedVolumeCount(string strId); QString getVolumeIcon(QString strVolumeId); - void OutputInfos(); + bool m_clickToEject = false; + Q_SIGNALS: void notifyDeviceRemoved(QString strDevId); private: FlashDiskData(); - bool m_clickToEject = false; - static FlashDiskData *m_instance; static QMutex m_mutex; diff --git a/src/interactivedialog.cpp b/src/interactivedialog.cpp index b5d44fb..7083855 100644 --- a/src/interactivedialog.cpp +++ b/src/interactivedialog.cpp @@ -309,7 +309,7 @@ void interactiveDialog::paintEvent(QPaintEvent *event) // path.addRoundedRect(rect, 12, 12); // path.drawRoundedRect // QRegion region(path.toFillPolygon().toPolygon()); -//// this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 +// this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明 // QWidget::paintEvent(event); // QStyleOption opt; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 13d62c3..9e7afea 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -88,12 +88,14 @@ MainWindow::~MainWindow() delete ifsettings; ifsettings = nullptr; } - for(int i = 1;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ - if (centralWidgetList[i] ) { - delete centralWidgetList[i]; - centralWidgetList[i] = nullptr; - } - } + QMap().swap(centralWidgetList); + +// for(int i = 0;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ +// if (centralWidgetList[i] ) { +// delete centralWidgetList[i]; +// centralWidgetList[i] = nullptr; +// } +// } } void MainWindow::initFlashDisk() @@ -158,6 +160,9 @@ void MainWindow::onRequestSendDesktopNotify(QString message, QString strIcon, QS QDBusConnection::sessionBus()); QList args; QMap hint; + if(strIcon == ""){ + strIcon = "drive-removable-media-usb"; //加密盘无法获取图标,使用默认图标 + } hint.insert("sound-name",notifySound); args << (tr("kylin device daemon")) << ((unsigned int) 0) @@ -356,10 +361,17 @@ void MainWindow::getDeviceInfo() g_free(strName); } getDriveIconsInfo(gdrive, driveInfo); + unsigned uVolumeSize = 0; + GList* Volumes = g_drive_get_volumes(gdrive); + if (Volumes) { + uVolumeSize = g_list_length(Volumes); + g_list_free(Volumes); + } driveInfo.isCanEject = g_drive_can_eject(gdrive); driveInfo.isCanStop = g_drive_can_stop(gdrive); driveInfo.isCanStart = g_drive_can_start(gdrive); driveInfo.isRemovable = g_drive_is_removable(gdrive); + driveInfo.lluVolSum = uVolumeSize; if(!isSystemRootDev(driveInfo.strId.c_str()) && getDevInterface(driveInfo.strId.c_str()) && (driveInfo.isCanEject || driveInfo.isCanStop || driveInfo.isRemovable)) { if(g_str_has_prefix(devPath,"/dev/sr") || g_str_has_prefix(devPath,"/dev/bus") || g_str_has_prefix(devPath,"/dev/sd") || g_str_has_prefix(devPath,"/dev/mmcblk")) { @@ -805,7 +817,7 @@ void MainWindow::onConvertUpdateWindow(QString strDevName, unsigned uDevType) { // uDevType: 0 drive , 1 volume, 2 mount if (uDevType == 1) { // not drive detached - qDebug()<<"----------MainWindowShow----------"; + qDebug()<<"----------onConvertUpdateWindow----------"; insertorclick = false; MainWindowShow(true); }else if(uDevType ==2){ @@ -931,20 +943,13 @@ void MainWindow::drive_disconnected_callback (GVolumeMonitor *monitor, GDrive *d } } p_this->m_dataFlashDisk->removeDriveInfo(driveInfo); - //Q_EMIT p_this->notifyDeviceRemoved(QString::fromStdString(driveInfo.strId)); if(p_this->m_dataFlashDisk->getValidInfoCount() == 0) { - for(int i = 1;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ - if (p_this->centralWidgetList[i] && !p_this->centralWidgetList[i]->isHidden()) { - p_this->centralWidgetList[i]->hide(); - delete p_this->centralWidgetList[i]; - p_this->centralWidgetList[i] = nullptr; - } - } + p_this->hideAllWidget(); p_this->ui->centralWidget->hide(); p_this->m_systray->hide(); } - if(!p_this->m_basewidget->isHidden()) - p_this->m_basewidget->hide(); +// if(!p_this->m_basewidget->isHidden()) +// p_this->m_basewidget->hide(); p_this->m_dataFlashDisk->OutputInfos(); } @@ -978,7 +983,14 @@ void MainWindow::volume_added_callback(GVolumeMonitor *monitor, GVolume *volume, bool isNewMount = false; char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); + unsigned uVolumeSize = 0; + GList* Volumes = g_drive_get_volumes(gdrive); + if (Volumes) { + uVolumeSize = g_list_length(Volumes); + g_list_free(Volumes); + } if((!gdrive)||(devPath == NULL)) { + qInfo()<<"gdrive or devepath is null"; FDVolumeInfo volumeInfo; bool isValidMount = true; char *devPath = g_volume_get_identifier(volume,G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); @@ -1095,6 +1107,7 @@ void MainWindow::volume_added_callback(GVolumeMonitor *monitor, GVolume *volume, driveInfo.isCanStop = g_drive_can_stop(gdrive); driveInfo.isCanStart = g_drive_can_start(gdrive); driveInfo.isRemovable = g_drive_is_removable(gdrive); + driveInfo.lluVolSum = uVolumeSize; if(!p_this->isSystemRootDev(driveInfo.strId.c_str()) && p_this->getDevInterface(driveInfo.strId.c_str()) && (driveInfo.isCanEject || driveInfo.isCanStop || driveInfo.isRemovable)) { @@ -1170,7 +1183,6 @@ void MainWindow::volume_added_callback(GVolumeMonitor *monitor, GVolume *volume, } g_object_unref(mount); } else { - qInfo()<<"ifGpartedBusy"<ifGpartedBusy(); if(p_this->ifsettings->get(IFAUTOLOAD).toBool()&&p_this->ifGpartedBusy()) { p_this->m_ismountadd = true; if (p_this->getDevInterface(volumeInfo.strId.c_str())){ @@ -1188,7 +1200,7 @@ void MainWindow::volume_added_callback(GVolumeMonitor *monitor, GVolume *volume, } } if (isNewMount) { - //qInfo()<<"cd data disk has mounted!"; + qInfo()<<"cd data disk has mounted!"; volumeInfo.isNewInsert = true; p_this->m_dataFlashDisk->addVolumeInfoWithDrive(driveInfo, volumeInfo); string strDevId = driveInfo.strId.empty()?volumeInfo.strId:driveInfo.strId; @@ -1237,8 +1249,14 @@ void MainWindow::volume_removed_callback(GVolumeMonitor *monitor, GVolume *volum if(p_this->m_dataFlashDisk->getValidInfoCount() == 0) { p_this->m_systray->hide(); } + if(g_str_has_prefix(volumeInfo.strId.c_str(),"/dev/sr")){ + p_this->hideAllWidget(true); + } p_this->m_dataFlashDisk->OutputInfos(); - Q_EMIT p_this->convertUpdateWindow(QString::fromStdString(volumeInfo.strName), 1); //emit a signal to update the MainMainShow slot + + if(FlashDiskData::getInstance()->getIfClickToEject()) + Q_EMIT p_this->convertUpdateWindow(QString::fromStdString(volumeInfo.strName), 1); //emit a signal to update the MainMainShow slot + FlashDiskData::getInstance()->m_clickToEject = false; } // when the volumes were mounted we add its mounts number @@ -1259,6 +1277,7 @@ void MainWindow::mount_added_callback(GVolumeMonitor *monitor, GMount *mount, Ma char *devPath = g_drive_get_identifier(gdrive,G_DRIVE_IDENTIFIER_KIND_UNIX_DEVICE); if (devPath != NULL) { driveInfo.strId = devPath; + qInfo()<<"drive id is"<getDevInterface(driveInfo.strId.c_str()))){ qInfo() << "---------------the devpath is "<getDriveIconsInfo(gdrive, driveInfo); + unsigned uVolumeSize = 0; + GList* Volumes = g_drive_get_volumes(gdrive); + if (Volumes) { + uVolumeSize = g_list_length(Volumes); + g_list_free(Volumes); + } driveInfo.isCanEject = g_drive_can_eject(gdrive); driveInfo.isCanStop = g_drive_can_stop(gdrive); driveInfo.isCanStart = g_drive_can_start(gdrive); driveInfo.isRemovable = g_drive_is_removable(gdrive); + driveInfo.lluVolSum = uVolumeSize; g_free(devPath); } #if UDFAUTOMOUNT @@ -1349,6 +1375,7 @@ void MainWindow::mount_added_callback(GVolumeMonitor *monitor, GMount *mount, Ma mountInfo.isNativeDev = g_file_is_native(root); //判断设备是本地设备or网络设备 char *mountUri = g_file_get_uri(root); //get挂载点的uri路径 if (mountUri) { + qInfo()<<"mount uri is"<m_dataFlashDisk->getValidInfoCount() >= 1) { if (isValidMount && isNewMount) { - //qInfo()<<"cd data disk has mounted!"; + qInfo()<<"cd data disk has mounted!"; string strDevId = driveInfo.strId.empty()?volumeInfo.strId:driveInfo.strId; if(volumeInfo.mountInfo.lluTotalSize >= 1){ Q_EMIT p_this->convertShowWindow(strDevId.c_str(), mountInfo.strUri.c_str()); @@ -1473,10 +1500,7 @@ void MainWindow::mount_removed_callback(GVolumeMonitor *monitor, GMount *mount, FDVolumeInfo volumeInfo; p_this->m_dataFlashDisk->getVolumeInfoByMount(mountInfo, volumeInfo); quint64 mountTickDiff = p_this->m_dataFlashDisk->getMountTickDiff(mountInfo); - p_this->m_dataFlashDisk->removeMountInfo(mountInfo); - if((g_str_has_prefix (volumeInfo.strId.c_str(), "/dev/sr"))) - p_this->m_dataFlashDisk->emitRemoveNotify(QString::fromStdString(mountInfo.strId),QString::fromStdString(volumeInfo.strId)); if(p_this->m_dataFlashDisk->getValidInfoCount() == 0) { p_this->m_systray->hide(); @@ -1640,13 +1664,9 @@ void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) { triggerType = 1; //It represents how we open the interface - for(int i = 1;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ - if (centralWidgetList[i] && !centralWidgetList[i]->isHidden() && !insertorclick) { - qDebug()<<"------清除centralWidgetList-------"; - centralWidgetList[i]->hide(); - delete centralWidgetList[i]; - centralWidgetList[i] = nullptr; - } + + if (!insertorclick) { + hideAllWidget(); } if(m_basewidget && !m_basewidget->isHidden() && !insertorclick){ @@ -1784,6 +1804,7 @@ void MainWindow::showFristWindow(quint64 uVolumeSum, hign = 112; if(uVolumeSum >=3 ){ hign = hign+(uVolumeSum-2)*FLASHDISKITEM_TITLE_HEIGHT; + ui->centralWidget->setEjectOnCentra(hign); } ui->centralWidget->setFixedSize(388, hign); @@ -1797,7 +1818,8 @@ void MainWindow::showFristWindow(quint64 uVolumeSum, if((uVolumeNum == uVolumeSum)&&(ui->centralWidget->isHidden()==true)){ m_basewidget->mainWindowVboxLayout->addWidget(ui->centralWidget); m_basewidget->setFixedSize(388, hign); - m_basewidget->m_hideTimer->start(3000); + interfaceHideTime->start(3000); + //m_basewidget->m_hideTimer->start(3000); ui->centralWidget->show(); m_basewidget->showBaseWindow(); moveBaseWidgetGeo(); @@ -1820,34 +1842,35 @@ void MainWindow::showMainWindow(int uVolumeNum, { qDebug()<<"遍历第"< 0) { hign = 112; if(uVolumeSum >=3 ){ hign = hign+(uVolumeSum-2)*FLASHDISKITEM_TITLE_HEIGHT; - //ui->centralWidget->setFixedSize(388, hign); + centralWidgetList[strDriveId]->setEjectOnCentra(hign); } } else { hign = 0; ui->centralWidget->setFixedSize(0, 0); } - centralWidgetList[uDiskCount]->setFixedSize(388, hign); - centralWidgetList[uDiskCount]->m_animLabel->setFixedSize(320, hign); + centralWidgetList[strDriveId]->setFixedSize(388, hign); + centralWidgetList[strDriveId]->m_animLabel->setFixedSize(320, hign); - if (uDiskCount>2){ - for (int i=2; i<=uDiskCount ;i++){ - uPositonY += centralWidgetList[i]->height(); - } - centralWidgetList[uDiskCount]->move(ui->centralWidget->x(),ui->centralWidget->y()-((uDiskCount-1)*FLASHDISKITEM_SPACE_HEIGHT)-uPositonY); - }else{ - centralWidgetList[uDiskCount]->move(ui->centralWidget->x(),ui->centralWidget->y()-((uDiskCount-1)*(hign+FLASHDISKITEM_SPACE_HEIGHT))); - } +// if (uDiskCount>2){ +// for (int i=2; i<=uDiskCount ;i++){ +// uPositonY += centralWidgetList[strDriveId]->height(); +// } +// centralWidgetList[strDriveId]->move(ui->centralWidget->x(),ui->centralWidget->y()-((uDiskCount-1)*FLASHDISKITEM_SPACE_HEIGHT)-uPositonY); +// }else{ +// centralWidgetList[strDriveId]->move(ui->centralWidget->x(),ui->centralWidget->y()-((uDiskCount-1)*(hign+FLASHDISKITEM_SPACE_HEIGHT))); +// } if(uVolumeNum<=2){ if(uVolumeNum == 1){ @@ -1859,29 +1882,37 @@ void MainWindow::showMainWindow(int uVolumeNum, vboxLayout1->addWidget(m_fdClickWidget); }else{ m_fdClickWidget->m_fristClickWidget = this->m_iconClickWidget; - m_fdClickWidget->setParent(centralWidgetList[uDiskCount]); + m_fdClickWidget->setParent(centralWidgetList[strDriveId]); m_fdClickWidget->move(5,25+uVolumeNum*15); m_fdClickWidget->show(); } - centralWidgetList[uDiskCount]->setLayout(vboxLayout1); + centralWidgetList[strDriveId]->setLayout(vboxLayout1); if(uVolumeNum == uVolumeSum){ - centralWidgetList[uDiskCount]->m_mainWindowHigh = hign; + centralWidgetList[strDriveId]->m_mainWindowHigh = hign; } if ((insertorclick)&&(uVolumeSum == uVolumeNum)){ if(ui->centralWidget!=NULL&&(ui->centralWidget->isHidden()==false)){ m_basewidget->mainWindowVboxLayout->addWidget(ui->centralWidget); } - for(int i = 0; isetProperty("useSystemStyleBlur", true); - m_basewidget->mainWindowVboxLayout->addWidget(centralWidgetList[i]); - } +// for(int i = 0; isetProperty("useSystemStyleBlur", true); +// m_basewidget->mainWindowVboxLayout->addWidget(centralWidgetList[i]); +// } +// } + QMap::iterator iter; + int i = 0; + for (iter = centralWidgetList.begin(); iter != centralWidgetList.end(); iter++) { + if(i <= FLASHDISKITEM_SHOWDISK_MAX) + m_basewidget->mainWindowVboxLayout->addWidget(iter.value()); + i++; } m_basewidget->setFixedSize(388, 0); m_basewidget->showBaseWindow(); - m_basewidget->m_hideTimer->start(3000); + interfaceHideTime->start(3000); + //m_basewidget->m_hideTimer->start(3000); moveBaseWidgetGeo(); } @@ -1986,18 +2017,24 @@ bool MainWindow::ifNewInsertVol() return true; } -void MainWindow::hideAllWidget(){ +void MainWindow::hideAllWidget(bool ifHidden) +{ - if(!ui->centralWidget->isHidden()){ - ui->centralWidget->hide(); - } - for(int i = 1;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ - if (centralWidgetList[i] && !centralWidgetList[i]->isHidden()) { - centralWidgetList[i]->hide(); - delete centralWidgetList[i]; - centralWidgetList[i] = nullptr; + if(ifHidden == false){ + QMap::iterator iter; + for (iter = centralWidgetList.begin(); iter != centralWidgetList.end(); iter++) { + if(!iter.value()->isHidden()) + iter.value()->hide(); + delete iter.value(); + } + }else{ + QMap::iterator iter; + for (iter = centralWidgetList.begin(); iter != centralWidgetList.end(); iter++) { + iter.value()->hide(); + delete iter.value(); } } + centralWidgetList.clear(); } void MainWindow::MainWindowShow(bool isUpdate) @@ -2055,6 +2092,9 @@ void MainWindow::MainWindowShow(bool isUpdate) //Convenient interface layout for all drives map& listDriveInfo = m_dataFlashDisk->getDevInfoWithDrive(); if (!listDriveInfo.empty()) { + if(!ui->centralWidget->isHidden()){ + ui->centralWidget->hide(); + } hideAllWidget(); map::iterator itDriveInfo = listDriveInfo.begin(); for ( ;itDriveInfo != listDriveInfo.end(); itDriveInfo++) { @@ -2320,6 +2360,7 @@ void MainWindow::MainWindowShow(bool isUpdate) unsigned uVolumeType = 0; // 0:normal file volume, 1: cddata, 2:tele dev if (!itVolumeInfo->second.mountInfo.strId.empty()) { string strMountUri = itVolumeInfo->second.mountInfo.strUri; + qInfo()<<"uri is "<second.strId.empty()) { @@ -2355,6 +2399,10 @@ void MainWindow::MainWindowShow(bool isUpdate) showMainWindow(uVolumeNum, uDiskCount, uVolumeSum,vboxLayout2, strDriveId, strVolumeId, strMountId, realTele, strApiName, lluTotalSize, strMountUri); } else { + if(isUpdate && itDriveInfo->second.lluVolSum != uVolumeSum){ + qDebug()<<"DriveId:"<second.strId)<<"DriveVolumeSum:"<second.lluVolSum<<"volume sum is "<setProperty("useSystemStyleBlur", true); - kdk::UkuiStyleHelper::self()->removeHeader(centralWidgetList[i]); - m_basewidget->mainWindowVboxLayout->addWidget(centralWidgetList[i]); + QMap::iterator iter; + int i = 0; + for (iter = centralWidgetList.begin(); iter != centralWidgetList.end(); iter++) { + if(i <= FLASHDISKITEM_SHOWDISK_MAX){ + iter.value()->setProperty("useSystemStyleBlur", true); + m_basewidget->mainWindowVboxLayout->addWidget(iter.value()); } + i++; } m_basewidget->setFixedSize(388, 0); //height自动适配高度 ui->centralWidget->hide(); @@ -2512,14 +2562,9 @@ void MainWindow::ifgetPinitMount() void MainWindow::onMaininterfacehide() { + m_basewidget->hide(); ui->centralWidget->hide(); - for(int i = 1;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ - if (centralWidgetList[i] && !centralWidgetList[i]->isHidden()) { - centralWidgetList[i]->hide(); - delete centralWidgetList[i]; - centralWidgetList[i] = nullptr; - } - } + hideAllWidget(); this->driveVolumeNum = 0; interfaceHideTime->stop(); m_dataFlashDisk->resetAllNewState(); @@ -2769,6 +2814,7 @@ void MainWindow::frobnitz_force_result_func(GDrive *source_object,GAsyncResult * gboolean success = FALSE; GError *err = nullptr; success = g_drive_eject_with_operation_finish (source_object, res, &err); + qInfo()<<"frobnitz_force_result_func"; if (!err) { FDDriveInfo driveInfo; @@ -2784,10 +2830,10 @@ void MainWindow::frobnitz_force_result_func(GDrive *source_object,GAsyncResult * g_free(strName); } - p_this->m_eject = new ejectInterface(p_this->ui->centralWidget,QString::fromStdString(driveInfo.strName), - NORMALDEVICE,QString::fromStdString(driveInfo.strId)); - p_this->m_eject->show(); - p_this->m_eject->moveEjectInterfaceRight(); +// p_this->m_eject = new ejectInterface(p_this->ui->centralWidget,QString::fromStdString(driveInfo.strName), +// NORMALDEVICE,QString::fromStdString(driveInfo.strId)); +// p_this->m_eject->show(); +// p_this->m_eject->moveEjectInterfaceRight(); FlashDiskData::getInstance()->removeDriveInfo(driveInfo); if(FlashDiskData::getInstance()->getValidInfoCount() == 0) { p_this->m_systray->hide(); @@ -2824,6 +2870,7 @@ void MainWindow::frobnitz_result_func(GDrive *source_object,GAsyncResult *res,Ma gboolean success = FALSE; GError *err = nullptr; success = g_drive_eject_with_operation_finish (source_object, res, &err); + qInfo()<<"frobnitz_result_func"; if (!err) { FDDriveInfo driveInfo; @@ -2839,10 +2886,11 @@ void MainWindow::frobnitz_result_func(GDrive *source_object,GAsyncResult *res,Ma g_free(strName); } - p_this->m_eject = new ejectInterface(p_this->ui->centralWidget,QString::fromStdString(driveInfo.strName), - NORMALDEVICE,QString::fromStdString(driveInfo.strId)); - p_this->m_eject->show(); - p_this->m_eject->moveEjectInterfaceRight(); +// p_this->m_eject = new ejectInterface(p_this->ui->centralWidget,QString::fromStdString(driveInfo.strName), +// NORMALDEVICE,QString::fromStdString(driveInfo.strId)); +// p_this->m_eject->show(); +// p_this->m_eject->moveEjectInterfaceRight(); + FlashDiskData::getInstance()->removeDriveInfo(driveInfo); if(FlashDiskData::getInstance()->getValidInfoCount() == 0) { p_this->m_systray->hide(); @@ -2941,16 +2989,16 @@ void MainWindow::onClickedEject(EjectDeviceInfo eDeviceInfo) m_curEjectDeviceInfo.pVoid = this; m_curEjectDeviceInfo.uFlag = G_MOUNT_UNMOUNT_NONE; qDebug()<<"-------- eject !----"; - for(int i = 1;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ - if (centralWidgetList[i]) { - qDebug()<<"-------- eject clean -----"; - centralWidgetList[i]->hide(); - delete centralWidgetList[i]; - centralWidgetList[i] = nullptr; - } - } +// for(int i = 0;i<=FLASHDISKITEM_SHOWDISK_MAX-1;i++){ +// if (centralWidgetList[i]) { +// centralWidgetList[i]->hide(); +// delete centralWidgetList[i]; +// centralWidgetList[i] = nullptr; +// } +// } + hideAllWidget(true); m_basewidget->hide(); - FlashDiskData::getInstance()->setClickToEject(); + FlashDiskData::getInstance()->m_clickToEject = true;; doRealEject(&m_curEjectDeviceInfo, G_MOUNT_UNMOUNT_NONE); } @@ -2969,6 +3017,7 @@ bool MainWindow::onDeviceErrored(GDrive* drive) GList* volumes = g_drive_get_volumes(drive); if (!volumes && !mRepairDialog.contains(device) && !g_strrstr(name, "FT ePass3000GM")) { RepairDialogBox* b = new RepairDialogBox(drive); + b->setAttribute(Qt::WA_DeleteOnClose); b->connect(b, &RepairDialogBox::repairOK, this, [=] (RepairDialogBox* d) { if (mRepairDialog.contains(d->getDeviceName())) { b->mshowflag = false; @@ -2987,6 +3036,7 @@ bool MainWindow::onDeviceErrored(GDrive* drive) if (!m && !g_strrstr(name, "FT ePass3000GM")) { if (volumeName && !mRepairDialog.contains(volumeName)) { RepairDialogBox* b = new RepairDialogBox(vv); + b->setAttribute(Qt::WA_DeleteOnClose); b->connect(b, &RepairDialogBox::remountDevice, this, &MainWindow::remountVolume); b->connect(b, &RepairDialogBox::repairOK, this, [=] (RepairDialogBox* d) { if (mRepairDialog.contains(d->getDeviceName())) { @@ -3244,6 +3294,7 @@ GAsyncReadyCallback MainWindow::fileEjectMountableCB(GFile *file, GAsyncResult * gboolean success = FALSE; GError *err = nullptr; success = g_file_eject_mountable_with_operation_finish(file, res, &err); + qInfo()<<"fileEjectMountableCB"; if (!err) { FDDriveInfo driveInfo; driveInfo.strId = peDeviceInfo->strDriveId.toStdString(); @@ -3289,10 +3340,10 @@ void MainWindow::driveStopCb(GObject* object, GAsyncResult* res, EjectDeviceInfo driveInfo.strId = peDeviceInfo->strDriveId.toStdString(); driveInfo.strName = peDeviceInfo->strDriveName.toStdString(); MainWindow* pThis = (MainWindow*)(peDeviceInfo->pVoid); - pThis->m_eject = new ejectInterface(pThis->ui->centralWidget,QString::fromStdString(driveInfo.strName), - NORMALDEVICE,QString::fromStdString(driveInfo.strId)); - pThis->m_eject->show(); - pThis->m_eject->moveEjectInterfaceRight(); +// pThis->m_eject = new ejectInterface(pThis->ui->centralWidget,QString::fromStdString(driveInfo.strName), +// NORMALDEVICE,QString::fromStdString(driveInfo.strId)); +// pThis->m_eject->show(); +// pThis->m_eject->moveEjectInterfaceRight(); FlashDiskData::getInstance()->removeDriveInfo(driveInfo); qInfo() << "driveStopCb:" <strMountUri<strVolumeId<strDriveId; pThis->m_dataFlashDisk->emitRemoveNotify(peDeviceInfo->strMountUri,peDeviceInfo->strVolumeId); diff --git a/src/mainwindow.h b/src/mainwindow.h index 3e6c22f..de09d9b 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -124,7 +124,7 @@ private: bool m_bIsMouseInCentral = false; qint64 m_nAppStartTimestamp = 0; // 进程启动时的时间戳 QString m_strSysRootDev; - FDFrame *centralWidgetList[FLASHDISKITEM_SHOWDISK_MAX] = {0}; + QMap centralWidgetList; baseWidget * m_basewidget; bool mIsrunning = false; @@ -217,7 +217,7 @@ private: bool ifBurnerBusy(QString strDev); bool ifGpartedBusy(); bool ifNewInsertVol(); - void hideAllWidget(); + void hideAllWidget(bool ifHidden = false); public Q_SLOTS: void iconActivated(QSystemTrayIcon::ActivationReason reason); diff --git a/src/qclickwidget.cpp b/src/qclickwidget.cpp index 7a6d504..df7a4c0 100644 --- a/src/qclickwidget.cpp +++ b/src/qclickwidget.cpp @@ -29,8 +29,8 @@ void frobnitz_force_result_func(GDrive *source_object,GAsyncResult *res,QClickWi if (!err) { findGDriveList()->removeOne(source_object); - p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,""); - p_this->m_eject->show(); +// p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,""); +// p_this->m_eject->show(); } else { @@ -64,8 +64,8 @@ void frobnitz_result_func(GDrive *source_object,GAsyncResult *res,QClickWidget * if (!err) { findGDriveList()->removeOne(source_object); - p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,""); - p_this->m_eject->show(); +// p_this->m_eject = new ejectInterface(p_this,g_drive_get_name(source_object),NORMALDEVICE,""); +// p_this->m_eject->show(); } else /*if(g_drive_can_stop(source_object) == true)*/