diff --git a/.gitignore b/.gitignore index 8a9d35c..f8246cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ *.user +build/ +.cursorindexingignore +.cursor +.specstory \ No newline at end of file diff --git a/app/cmdmanager.cpp b/app/cmdmanager.cpp index afa9e4b..f2d6eab 100644 --- a/app/cmdmanager.cpp +++ b/app/cmdmanager.cpp @@ -4,6 +4,7 @@ #include "cmdmanager.h" #include +#include CMDManager *CMDManager::instance() { @@ -38,9 +39,12 @@ QString CMDManager::getPath() { QStringList positionalArguments = m_parser.positionalArguments(); if (positionalArguments.count() > 0) { - return m_parser.positionalArguments().at(0); + QString path = m_parser.positionalArguments().at(0); + qDebug() << "CMDManager: Found device path:" << path; + return path; } + qDebug() << "CMDManager: No device path provided in arguments"; return QString(); } @@ -51,14 +55,19 @@ QStringList CMDManager::positionalArguments() const void CMDManager::showHelp(int exitCode) { + qDebug() << "CMDManager: Showing help with exit code:" << exitCode; return m_parser.showHelp(exitCode); } int CMDManager::getWinId() { QString winId = m_parser.value(m_modelModeOpt); - if(winId.isEmpty()) + qDebug() << "CMDManager: Raw window ID value:" << (winId.isEmpty() ? "empty" : winId); + + if(winId.isEmpty()) { + qDebug() << "CMDManager: No window ID provided, returning -1"; return -1; + } return winId.toInt(); } diff --git a/app/singletonapp.cpp b/app/singletonapp.cpp index 67643ea..11cb107 100644 --- a/app/singletonapp.cpp +++ b/app/singletonapp.cpp @@ -20,6 +20,7 @@ void SingletonApp::initConnections() QString SingletonApp::getServerPathByKey(const QString &key) { QString serverPath = QString("%1/%2").arg(getServerRootPath(), key); + qDebug() << "SingletonApp: Generated server path:" << serverPath << "for key:" << key; return serverPath; } @@ -52,18 +53,28 @@ SingletonApp *SingletonApp::instance() bool SingletonApp::setSingletonApplication(const QString &key) { + qDebug() << "SingletonApp: Setting up singleton application with key:" << key; m_key = key; QString serverPath = getServerPathByKey(key); + + // Try to connect to existing server + qDebug() << "SingletonApp: Checking if another instance is already running"; QLocalSocket socket; socket.connectToServer(serverPath); bool ret = socket.waitForConnected(1000); if(ret){ + qDebug() << "SingletonApp: Another instance detected, sending multi-process signal"; socket.write("MultiProcess"); socket.flush(); + qDebug() << "SingletonApp: Failed to create singleton - another instance is running"; return false; } - + + qDebug() << "SingletonApp: No existing instance found, creating new server"; + // Remove any stale server QLocalServer::removeServer(serverPath); + + // Create new server ret = m_server.listen(serverPath); return ret; } @@ -71,11 +82,14 @@ bool SingletonApp::setSingletonApplication(const QString &key) void SingletonApp::readData() { QLocalSocket* socket = qobject_cast(sender()); - if(!socket) + if(!socket) { + qDebug() << "SingletonApp: readData called but sender is not a QLocalSocket"; return; + } QByteArray data = socket->readAll(); - qDebug () << "New connection requested:" << data; + qDebug() << "SingletonApp: Received data from client connection:" << data; + qDebug() << "SingletonApp: Client connection data size:" << data.size() << "bytes"; } void SingletonApp::handleConnection() diff --git a/main.cpp b/main.cpp index ca1487a..304aa28 100755 --- a/main.cpp +++ b/main.cpp @@ -28,6 +28,8 @@ DCORE_USE_NAMESPACE int main(int argc, char *argv[]) { + qDebug() << "Main: Starting dde-device-formatter application"; + // 设置Deepin平台主题 if (qgetenv("QT_QPA_PLATFORMTHEME").isEmpty()) { qputenv("QT_QPA_PLATFORMTHEME", "deepin"); @@ -46,22 +48,32 @@ int main(int argc, char *argv[]) bool isWayland = false; if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) { isWayland = true; + qDebug() << "Main: Detected Wayland session"; + } else { + qDebug() << "Main: Detected X11 session"; } DApplication a(argc, argv); //Singleton app handle bool isSingletonApp = SingletonApp::instance()->setSingletonApplication("dde-device-formatter"); - if (!isSingletonApp) + if (!isSingletonApp) { + qDebug() << "Main: Another instance is already running, exiting"; return 0; + } //Load translation QTranslator translator; QString locale = QLocale::system().name(); QString qmFile = QString("%1/dde-device-formatter_%2.qm").arg(QString::fromLatin1(TRANSLATIONS_DIR), locale); + qDebug() << "Main: System locale:" << locale; + qDebug() << "Main: Translation file path:" << qmFile; if (translator.load(qmFile)) { a.installTranslator(&translator); + qDebug() << "Main: Translation file loaded and installed successfully"; + } else { + qDebug() << "Main: Failed to load translation file, using default language"; } a.setOrganizationName("deepin"); @@ -75,6 +87,7 @@ int main(int argc, char *argv[]) // Check if we need display help text. if (CMDManager::instance()->positionalArguments().isEmpty()) { + qDebug() << "Main: No positional arguments provided, showing help"; CMDManager::instance()->showHelp(); } @@ -90,6 +103,7 @@ int main(int argc, char *argv[]) //Check if the device is read-only UDisksBlock blk(path); if (blk.isReadOnly()) { + qDebug() << "Main: Device is read-only, cannot format"; QString message = QObject::tr("The device is read-only"); MessageDialog d(message, 0); d.exec(); @@ -103,10 +117,12 @@ int main(int argc, char *argv[]) w->move(rect.x(), rect.y()); if (CMDManager::instance()->isSet("m")) { + qDebug() << "Main: Model mode enabled, setting window parent"; int parentWinId = CMDManager::instance()->getWinId(); int winId = w->winId(); if (parentWinId != -1 && !isWayland) { + qDebug() << "Main: Setting transient window hint for X11"; Display *display = QX11Info::display(); if (display) { XSetTransientForHint(display, (Window)winId, (Window)parentWinId); @@ -115,5 +131,7 @@ int main(int argc, char *argv[]) } int code = a.exec(); + + qDebug() << "Main: Performing quick exit"; quick_exit(code); } diff --git a/utils/udisksutils.cpp b/utils/udisksutils.cpp index b728974..8da094c 100644 --- a/utils/udisksutils.cpp +++ b/utils/udisksutils.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -35,25 +36,34 @@ bool UDisksBlock::isReadOnly() const QString UDisksBlock::displayName() const { if (blk->mountPoints().contains(QByteArray("/\0", 2))) { + qDebug() << "UDisksBlock: Device is system disk"; return QCoreApplication::tr("System Disk"); } - if (blk->idLabel().length() == 0) { + + QString label = blk->idLabel(); + if (label.length() == 0) { if (blk->isEncrypted() && blk->cleartextDevice().length() <= 1) { - return QCoreApplication::tr("%1 Encrypted").arg(QLocale::system().formattedDataSize(sizeTotal())); + QString name = QCoreApplication::tr("%1 Encrypted").arg(QLocale::system().formattedDataSize(sizeTotal())); + qDebug() << "UDisksBlock: Device is encrypted, display name:" << name; + return name; } - return QCoreApplication::tr("%1 Volume").arg(QLocale::system().formattedDataSize(sizeTotal())); + QString name = QCoreApplication::tr("%1 Volume").arg(QLocale::system().formattedDataSize(sizeTotal())); + qDebug() << "UDisksBlock: Device has no label, using volume name:" << name; + return name; } else { - return blk->idLabel(); + qDebug() << "UDisksBlock: Device label:" << label; + return label; } } QString UDisksBlock::iconName() const { QScopedPointer drv(DDiskManager::createDiskDevice(blk->drive())); - if (drv->media() == "thumb" || drv->removable() || drv->mediaRemovable() || drv->ejectable()) { - return QString("drive-removable-media") + (blk->isEncrypted() ? "-encrypted" : ""); - } - return QString("drive-harddisk") + (blk->isEncrypted() ? "-encrypted" : ""); + bool isRemovable = (drv->media() == "thumb" || drv->removable() || drv->mediaRemovable() || drv->ejectable()); + QString iconName = QString(isRemovable ? "drive-removable-media" : "drive-harddisk") + (blk->isEncrypted() ? "-encrypted" : ""); + + qDebug() << "UDisksBlock: Device type - removable:" << isRemovable << ", encrypted:" << blk->isEncrypted() << ", icon:" << iconName; + return iconName; } QString UDisksBlock::fsType() const @@ -73,15 +83,18 @@ qint64 UDisksBlock::sizeUsed() const rblk.reset(DDiskManager::createBlockDevice(blk->cleartextDevice())); } if (!rblk->hasFileSystem()) { + qDebug() << "UDisksBlock: Device has no filesystem, cannot calculate used size"; return -1; } QString mp; if (!rblk->mountPoints().empty()) { mp = rblk->mountPoints().front(); + qDebug() << "UDisksBlock: Device mount point:" << mp; } if (mp.isEmpty()) { + qDebug() << "UDisksBlock: Device is not mounted, cannot calculate used size"; return -1; } diff --git a/view/mainwindow.cpp b/view/mainwindow.cpp index 2656e4f..594c5ae 100755 --- a/view/mainwindow.cpp +++ b/view/mainwindow.cpp @@ -101,20 +101,29 @@ void MainWindow::initConnect() { connect(m_comfirmButton, &QPushButton::clicked, this, &MainWindow::nextStep); connect(m_diskm.data(), &DDiskManager::jobAdded, [this](const QString &jobs) { + qDebug() << "MainWindow: Disk manager job added:" << jobs; + QScopedPointer job(DDiskManager::createJob(jobs)); if (job->operation().contains("format") && job->objects().contains(UDisksBlock(m_formatPath)->path())) { + qDebug() << "MainWindow: Found matching format job for device:" << m_formatPath; + qDebug() << "MainWindow: Job operation:" << job->operation(); + m_job.reset(DDiskManager::createJob(jobs)); //非快速格式化按照正常进度显示 if (m_job->operation().contains("erase")) { + qDebug() << "MainWindow: Setting up full format with erase operation"; connect(m_job.data(), &DUDisksJob::progressChanged, [this](double p) { + qDebug() << "MainWindow: Format progress:" << (p * 100) << "%"; m_formatingPage->setProgress(p); }); - connect(m_job.data(), &DUDisksJob::completed, [this](bool r, QString) { + connect(m_job.data(), &DUDisksJob::completed, [this](bool r, QString msg) { + qDebug() << "MainWindow: Full format completed, result:" << r << ", message:" << msg; this->onFormatingFinished(r); }); } //快速格式化不会收到进度更新的信号,这里模拟一个进度条增长的过程 else if (m_job->operation().contains("mkfs")) { + qDebug() << "MainWindow: Setting up quick format simulation"; QTimer *timer = new QTimer(); m_simulationProgressValue = 0; connect(timer, &QTimer::timeout, [this, timer]() { @@ -128,7 +137,8 @@ void MainWindow::initConnect() }); timer->start(300); - connect(m_job.data(), &DUDisksJob::completed, [this, timer](bool r, QString) { + connect(m_job.data(), &DUDisksJob::completed, [this, timer](bool r, QString msg) { + qDebug() << "MainWindow: Quick format completed, result:" << r << ", message:" << msg; timer->disconnect(); timer->stop(); m_simulationProgressValue = 0; @@ -144,26 +154,32 @@ void MainWindow::initConnect() } } }); + connect(m_diskm.data(), &DDiskManager::diskDeviceRemoved, this, [this]() { + qDebug() << "MainWindow: Disk device removed event triggered"; + bool quit = true; QStringList &&blkDevStrGroup = DDiskManager::blockDevices({}); + qDebug() << "MainWindow: Checking remaining block devices, count:" << blkDevStrGroup.size(); + for (auto blkDevStr : blkDevStrGroup) { QScopedPointer blkDev(DDiskManager::createBlockDevice(blkDevStr)); if (blkDev) { QStringList blDevStrArray = blkDevStr.split(QDir::separator()); QString tagName = blDevStrArray.isEmpty() ? "" : blDevStrArray.last(); QString devPath = "/dev/" + tagName; - qDebug() << "block device:" << devPath << "exists"; + qDebug() << "MainWindow: Found remaining block device:" << devPath; // 当前计算机一个块设备被移除后,检查剩余的块设备是否包含将要格式化的设备 // 若依然包含,则说明被移除的设备不是将要格式化的设备,因此格式化程序不退出 if (devPath == m_formatPath) { - qDebug() << "block device:" << devPath << "not removed"; + qDebug() << "MainWindow: Target device" << devPath << "still exists, not quitting"; quit = false; } } } if (quit) { + qDebug() << "MainWindow: Target device removed, closing application"; this->close(); this->deleteLater(); ::exit(0); @@ -173,29 +189,47 @@ void MainWindow::initConnect() void MainWindow::formatDevice() { + qDebug() << "MainWindow: Starting device format process"; + qDebug() << "MainWindow: Format path:" << m_formatPath; + qDebug() << "MainWindow: Selected filesystem:" << m_mainPage->getSelectedFs(); + qDebug() << "MainWindow: Device label:" << m_mainPage->getLabel(); + qDebug() << "MainWindow: Should erase:" << m_mainPage->shouldErase(); + DWindowManagerHelper::setMotifFunctions(windowHandle(), DWindowManagerHelper::FUNC_CLOSE, false); setCloseButtonVisible(false); + qDebug() << "MainWindow: Disabled window close function during formatting"; QtConcurrent::run([=] { + qDebug() << "MainWindow: Format thread started"; + UDisksBlock blk(m_formatPath); if (!blk->mountPoints().empty()) { + qDebug() << "MainWindow: Device is mounted, attempting to unmount"; + qDebug() << "MainWindow: Mount points:" << blk->mountPoints(); + blk->unmount({}); QDBusError lastError = blk->lastError(); if (lastError.isValid()) { - qWarning() << "failed to unmount the dev: " << blk->path() << " by: " << lastError.name() << " : " << lastError.message(); + qWarning() << "MainWindow: Failed to unmount device:" << blk->path() << "Error:" << lastError.name() << ":" << lastError.message(); QMetaObject::invokeMethod(this, std::bind(&MainWindow::onFormatingFinished, this, false), Qt::ConnectionType::QueuedConnection); return; } + qDebug() << "MainWindow: Device unmounted successfully"; + } else { + qDebug() << "MainWindow: Device is not mounted, proceeding with format"; } + QVariantMap opt = { { "label", m_mainPage->getLabel() } }; if (m_mainPage->shouldErase()) opt["erase"] = "zero"; blk->format(m_mainPage->getSelectedFs(), opt); QDBusError lastError = blk->lastError(); if (lastError.isValid()) { - qWarning() << "failed to format the dev: " << blk->path() << " by: " << lastError.name() << " : " << lastError.message(); + qWarning() << "MainWindow: Failed to format device:" << blk->path() << "Error:" << lastError.name() << ":" << lastError.message(); QMetaObject::invokeMethod(this, std::bind(&MainWindow::onFormatingFinished, this, false), Qt::ConnectionType::QueuedConnection); return; } + + qDebug() << "MainWindow: Format operation initiated successfully"; }); } @@ -206,13 +240,17 @@ bool MainWindow::checkBackup() void MainWindow::nextStep() { + qDebug() << "MainWindow: Next step triggered, current step:" << m_currentStep; + switch (m_currentStep) { case Normal: + qDebug() << "MainWindow: Switching from Normal to Warn page"; m_pageStack->setCurrentWidget(m_warnPage); m_currentStep = Warn; m_comfirmButton->setText(tr("Continue")); break; case Warn: + qDebug() << "MainWindow: Switching from Warn to Formatting page"; m_pageStack->setCurrentWidget(m_formatingPage); m_currentStep = Formating; m_comfirmButton->setText(tr("Formatting...")); @@ -220,53 +258,67 @@ void MainWindow::nextStep() formatDevice(); break; case Finished: + qDebug() << "MainWindow: Format completed, quitting application"; qApp->quit(); break; case FormattError: + qDebug() << "MainWindow: Switching from Error back to Main page for retry"; m_pageStack->setCurrentWidget(m_mainPage); m_currentStep = Normal; break; case RemovedWhenFormattingError: + qDebug() << "MainWindow: Device removed during formatting, quitting application"; qApp->quit(); break; default: + qDebug() << "MainWindow: Unknown step:" << m_currentStep; break; } } void MainWindow::onFormatingFinished(const bool &successful) { + qDebug() << "MainWindow: Formatting finished, successful:" << successful; + DWindowManagerHelper::setMotifFunctions(windowHandle(), DWindowManagerHelper::FUNC_CLOSE, true); setCloseButtonVisible(true); + qDebug() << "MainWindow: Re-enabled window close function"; if (successful) { + qDebug() << "MainWindow: Format successful, showing finish page"; m_currentStep = Finished; m_comfirmButton->setText(tr("Done")); m_comfirmButton->setEnabled(true); m_pageStack->setCurrentWidget(m_finishPage); QTimer::singleShot(0, this, [this] { + qDebug() << "MainWindow: Attempting to mount formatted device"; UDisksBlock(this->m_formatPath)->mount({}); }); } else { + qDebug() << "MainWindow: Format failed, checking device status"; if (!QFile::exists(m_formatPath)) { + qDebug() << "MainWindow: Device file does not exist, device was removed"; m_currentStep = RemovedWhenFormattingError; m_comfirmButton->setText(tr("Quit")); m_errorPage->setErrorMsg(tr("Your disk has been removed")); } else { + qDebug() << "MainWindow: Device still exists, format operation failed"; m_currentStep = FormattError; m_errorPage->setErrorMsg(tr("Failed to format the device")); m_comfirmButton->setText(tr("Reformat")); } m_comfirmButton->setEnabled(true); m_pageStack->setCurrentWidget(m_errorPage); + qDebug() << "MainWindow: Showing error page with step:" << m_currentStep; } } void MainWindow::closeEvent(QCloseEvent *event) { + qDebug() << "MainWindow: Close event triggered"; DDialog::closeEvent(event); - + qDebug() << "MainWindow: Exiting application"; qApp->exit(); }