-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmainwindow.cc
More file actions
179 lines (156 loc) · 7.66 KB
/
mainwindow.cc
File metadata and controls
179 lines (156 loc) · 7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "mainwindow.hpp"
#include "windowsintegration.hpp"
#include <QApplication>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Create central widget and main layout
QWidget *centralWidget = new QWidget(this);
setCentralWidget(centralWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);
// Title
QLabel *titleLabel = new QLabel("Windows Integration Manager", this);
titleLabel->setStyleSheet("font-size: 16px; font-weight: bold; margin: 10px;");
mainLayout->addWidget(titleLabel);
// Status display
QLabel *statusLabel = new QLabel("Checking Windows integration status...", this);
statusLabel->setAlignment(Qt::AlignCenter);
statusLabel->setFrameStyle(QFrame::Box);
statusLabel->setStyleSheet("padding: 10px; background-color: #f0f0f0; border-radius: 5px;");
mainLayout->addWidget(statusLabel);
// My Computer integration checkbox
QCheckBox *myComputerCheckBox = new QCheckBox("Show application icon in 'This PC'", this);
mainLayout->addWidget(myComputerCheckBox);
// Button area
QHBoxLayout *buttonLayout = new QHBoxLayout();
QPushButton *refreshButton = new QPushButton("Refresh Status", this);
buttonLayout->addWidget(refreshButton);
buttonLayout->addStretch();
QPushButton *aboutButton = new QPushButton("About", this);
buttonLayout->addWidget(aboutButton);
mainLayout->addLayout(buttonLayout);
// Information
QLabel *infoLabel
= new QLabel("Note: When enabled, the application icon will appear in Windows 'This PC' "
"alongside your drives.\n"
"You may need to restart File Explorer or log out and back in to see changes.",
this);
infoLabel->setStyleSheet("color: #666; font-size: 12px; margin-top: 20px;");
infoLabel->setWordWrap(true);
mainLayout->addWidget(infoLabel);
mainLayout->addStretch();
// Set window properties
setWindowTitle("Windows Integration Example");
resize(600, 280);
// Helper lambda function to update status label
auto updateStatusLabel = [](QLabel *label, bool isRegistered) {
if (isRegistered) {
label->setText(
"✅ My Computer integration is ENABLED - Application icon appears in 'This PC'");
label->setStyleSheet(
"padding: 10px; background-color: #e8f5e8; border-radius: 5px; color: #2e7d32;");
} else {
label->setText("❌ My Computer integration is DISABLED - No icon in 'This PC'");
label->setStyleSheet(
"padding: 10px; background-color: #ffebee; border-radius: 5px; color: #c62828;");
}
label->setText(label->text() + " (Windows Registry)");
};
static const auto GUID = "{789183FC-5E6B-4948-8C18-7AF0BBE527A1}";
// Initialize checkbox state
bool isRegistered = Utils::isRegisteredInMyComputer(GUID);
myComputerCheckBox->setChecked(isRegistered);
updateStatusLabel(statusLabel, isRegistered);
// Connect signals and slots using lambdas
connect(myComputerCheckBox,
&QCheckBox::toggled,
this,
[this, statusLabel, updateStatusLabel](bool checked) {
// Show confirmation dialog
QMessageBox::StandardButton reply = QMessageBox::question(
this,
checked ? "Enable My Computer Integration" : "Disable My Computer Integration",
checked
? "Are you sure you want to add the application icon to 'This PC'? "
"The icon will appear alongside your drives."
: "Are you sure you want to remove the application icon from 'This PC'?",
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (reply == QMessageBox::Yes) {
// Set integration state
bool success = Utils::setRegisteredInMyComputer(checked, GUID);
// Update status display
updateStatusLabel(statusLabel, checked);
// Show operation result
if (success) {
if (checked) {
QMessageBox::information(this,
"Success",
"Application has been added to 'This PC'!\n\n"
"Note: You may need to:\n"
"• Restart File Explorer, or\n"
"• Log out and back in, or\n"
"• Press F5 to refresh\n"
"to see the changes.");
} else {
QMessageBox::information(
this,
"Success",
"Application has been removed from 'This PC'!\n\n"
"Note: You may need to refresh File Explorer to see the changes.");
}
} else {
QMessageBox::warning(this,
"Operation Failed",
"Failed to update Windows integration settings.\n"
"Please try again or check application permissions.");
// Revert checkbox on failure
QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
if (checkBox) {
checkBox->blockSignals(true);
checkBox->setChecked(!checked);
checkBox->blockSignals(false);
}
updateStatusLabel(statusLabel, !checked);
}
} else {
// User canceled, revert checkbox state
QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
if (checkBox) {
checkBox->blockSignals(true);
checkBox->setChecked(!checked);
checkBox->blockSignals(false);
}
}
});
connect(refreshButton,
&QPushButton::clicked,
this,
[this, statusLabel, myComputerCheckBox, updateStatusLabel]() {
bool isRegistered = Utils::isRegisteredInMyComputer(GUID);
myComputerCheckBox->blockSignals(true);
myComputerCheckBox->setChecked(isRegistered);
myComputerCheckBox->blockSignals(false);
updateStatusLabel(statusLabel, isRegistered);
QMessageBox::information(this,
"Refreshed",
"Windows integration status has been refreshed!");
});
connect(aboutButton, &QPushButton::clicked, this, []() {
QMessageBox::about(
nullptr,
"About Windows Integration",
"Windows Integration Manager\n\n"
"Demonstrates how to integrate Qt applications with Windows Shell.\n"
"This feature adds application icons to Windows 'This PC' for quick access.\n\n"
"Uses Windows Registry to create shell namespace extensions.");
});
}
MainWindow::~MainWindow() {}