Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.user
build/
.cursorindexingignore
.cursor
.specstory
13 changes: 11 additions & 2 deletions app/cmdmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "cmdmanager.h"
#include <QStringList>

Check warning on line 6 in app/cmdmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStringList> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 7 in app/cmdmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

CMDManager *CMDManager::instance()
{
Expand Down Expand Up @@ -38,9 +39,12 @@
{
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();
}

Expand All @@ -51,14 +55,19 @@

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();
}

Expand Down
20 changes: 17 additions & 3 deletions app/singletonapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -52,30 +53,43 @@ 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;
}

void SingletonApp::readData()
{
QLocalSocket* socket = qobject_cast<QLocalSocket*>(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()
Expand Down
20 changes: 19 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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();
}

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -115,5 +131,7 @@ int main(int argc, char *argv[])
}

int code = a.exec();

qDebug() << "Main: Performing quick exit";
quick_exit(code);
}
29 changes: 21 additions & 8 deletions utils/udisksutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#include "udisksutils.h"

#include <QCoreApplication>

Check warning on line 7 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLocale>

Check warning on line 8 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLocale> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStorageInfo>

Check warning on line 9 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStorageInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 10 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <dblockdevice.h>

Check warning on line 12 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dblockdevice.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <ddiskdevice.h>

Check warning on line 13 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <ddiskdevice.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <ddiskmanager.h>

UDisksBlock::UDisksBlock(const QString &devnode)
Expand All @@ -32,28 +33,37 @@
* Consult the DFMFileInfo class in dde-file-manager first! Make sure
* reasonable parity is maintained between these two classes.
*/
QString UDisksBlock::displayName() const

Check warning on line 36 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'displayName' is never used.
{
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

Check warning on line 59 in utils/udisksutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'iconName' is never used.
{
QScopedPointer<DDiskDevice> 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
Expand All @@ -73,15 +83,18 @@
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;
}

Expand Down
Loading