Skip to content

Commit 5b4481f

Browse files
authored
Merge pull request #11 from arch-linux-gui/qt6/c++
More fixes to Qt6 version
2 parents 64eb058 + 467e396 commit 5b4481f

File tree

5 files changed

+153
-17
lines changed

5 files changed

+153
-17
lines changed

src/core/package_manager.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ void PackageManager::installPackage(const QString& packageName, const QString& r
6969
Logger::info(QString("Installing package: %1 from %2").arg(packageName, repository.isEmpty() ? "default" : repository));
7070
emit operationStarted(QString("Installing %1...").arg(packageName));
7171

72-
// Determine if this is an AUR package
73-
bool isAUR = repository.toLower() == "aur";
72+
// Determine if this is an AUR package (not from official repos or chaotic-aur)
73+
QString repoLower = repository.toLower();
74+
bool isAUR = repoLower == "aur";
7475
QString helper = getHelperName();
7576

7677
QString command;
7778
if (isAUR && (m_helper == Helper::Yay || m_helper == Helper::Paru)) {
7879
// AUR packages - run helper as regular user (no pkexec)
7980
command = QString("%1 -S %2 --noconfirm").arg(helper, packageName);
8081
} else {
81-
// Official repos need root access
82+
// Official repos and chaotic-aur need root access and use pacman
8283
command = QString("pkexec pacman -S %1 --noconfirm").arg(packageName);
8384
}
8485

@@ -103,16 +104,17 @@ void PackageManager::updatePackage(const QString& packageName, const QString& re
103104
Logger::info(QString("Updating package: %1 from %2").arg(packageName, repository.isEmpty() ? "default" : repository));
104105
emit operationStarted(QString("Updating %1...").arg(packageName));
105106

106-
// Determine if this is an AUR package
107-
bool isAUR = repository.toLower() == "aur";
107+
// Determine if this is an AUR package (not from official repos or chaotic-aur)
108+
QString repoLower = repository.toLower();
109+
bool isAUR = repoLower == "aur";
108110
QString helper = getHelperName();
109111

110112
QString command;
111113
if (isAUR && (m_helper == Helper::Yay || m_helper == Helper::Paru)) {
112114
// AUR packages - run helper as regular user (no pkexec)
113115
command = QString("%1 -S %2 --noconfirm").arg(helper, packageName);
114116
} else {
115-
// Official repos need root access
117+
// Official repos and chaotic-aur need root access and use pacman
116118
command = QString("pkexec pacman -S %1 --noconfirm").arg(packageName);
117119
}
118120

src/gui/home_widget.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void HomeWidget::setupUi() {
4949
}
5050

5151
void HomeWidget::loadFeaturedPackages() {
52-
// Featured packages list
52+
// Featured packages list with initial repositories
5353
m_featuredPackages = {
5454
{"firefox", "Latest", "Fast, Private & Safe Web Browser", "extra"},
5555
{"gimp", "Latest", "GNU Image Manipulation Program", "extra"},
@@ -65,6 +65,24 @@ void HomeWidget::loadFeaturedPackages() {
6565
{"zoom", "Latest", "Video Conferencing and Web Conferencing Service", "AUR"}
6666
};
6767

68+
// Check if packages marked as AUR are actually available in automated repos (like chaotic-aur)
69+
for (auto& pkg : m_featuredPackages) {
70+
if (pkg.repository.toLower() == "aur") {
71+
Logger::debug(QString("Checking if AUR package %1 is available in official repos...").arg(pkg.name));
72+
PackageInfo repoInfo = AlpmWrapper::instance().getPackageInfo(pkg.name);
73+
if (!repoInfo.name.isEmpty() && !repoInfo.repository.isEmpty()) {
74+
// Package found in automated repos, use that repository instead
75+
pkg.repository = repoInfo.repository;
76+
pkg.version = repoInfo.version;
77+
pkg.description = repoInfo.description;
78+
Logger::info(QString("✅ Package %1 found in %2 repository, will use pacman instead of AUR helper")
79+
.arg(pkg.name, pkg.repository));
80+
} else {
81+
Logger::debug(QString("Package %1 not found in official repos, will use AUR helper").arg(pkg.name));
82+
}
83+
}
84+
}
85+
6886
Logger::info(QString("Loaded %1 featured packages").arg(m_featuredPackages.size()));
6987
}
7088

src/gui/mainwindow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ MainWindow::MainWindow(QWidget* parent)
1717
: QMainWindow(parent)
1818
, m_tabWidget(std::make_unique<QTabWidget>(this)) {
1919

20-
setupUi();
21-
loadStyleSheet();
22-
23-
// Initialize ALPM
20+
// Initialize ALPM before creating widgets that might need it
2421
if (!AlpmWrapper::instance().initialize()) {
2522
QMessageBox::critical(this, "Error",
2623
"Failed to initialize package manager. Please check your system configuration.");
2724
Logger::error("Failed to initialize ALPM in MainWindow");
2825
}
2926

27+
setupUi();
28+
loadStyleSheet();
29+
3030
Logger::info("MainWindow created successfully");
3131
}
3232

src/gui/settings_widget.cpp

Lines changed: 120 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <QFile>
88
#include <QTextStream>
99
#include <QProcess>
10+
#include <QScrollArea>
11+
#include <QWidget>
1012

1113
SettingsWidget::SettingsWidget(QWidget* parent)
1214
: QWidget(parent)
@@ -18,6 +20,9 @@ SettingsWidget::SettingsWidget(QWidget* parent)
1820
, m_chaoticAurGroup(nullptr)
1921
, m_setupChaoticButton(nullptr)
2022
, m_removeChaoticButton(nullptr)
23+
, m_maintenanceGroup(nullptr)
24+
, m_removeLockButton(nullptr)
25+
, m_syncReposButton(nullptr)
2126
, m_applyButton(nullptr)
2227
, m_revertButton(nullptr)
2328
, m_statusLabel(nullptr)
@@ -31,11 +36,25 @@ SettingsWidget::SettingsWidget(QWidget* parent)
3136
}
3237

3338
void SettingsWidget::setupUi() {
34-
auto* mainLayout = new QVBoxLayout(this);
39+
// Create main layout for the widget
40+
auto* outerLayout = new QVBoxLayout(this);
41+
outerLayout->setContentsMargins(0, 0, 0, 0);
42+
43+
// Create scroll area
44+
auto* scrollArea = new QScrollArea(this);
45+
scrollArea->setWidgetResizable(true);
46+
scrollArea->setFrameShape(QFrame::NoFrame);
47+
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
48+
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
49+
50+
// Create content widget that will be scrollable
51+
auto* contentWidget = new QWidget();
52+
auto* mainLayout = new QVBoxLayout(contentWidget);
3553
mainLayout->setSpacing(20);
54+
mainLayout->setContentsMargins(10, 10, 10, 10);
3655

3756
// Title
38-
auto* titleLabel = new QLabel("Settings", this);
57+
auto* titleLabel = new QLabel("Settings", contentWidget);
3958
auto titleFont = titleLabel->font();
4059
titleFont.setPointSize(24);
4160
titleFont.setBold(true);
@@ -55,7 +74,7 @@ void SettingsWidget::setupUi() {
5574
mainLayout->addWidget(m_maintenanceGroup);
5675

5776
// Status label
58-
m_statusLabel = new QLabel(this);
77+
m_statusLabel = new QLabel(contentWidget);
5978
m_statusLabel->setAlignment(Qt::AlignCenter);
6079
m_statusLabel->setStyleSheet("QLabel { color: #0066cc; padding: 10px; }");
6180
m_statusLabel->hide();
@@ -65,13 +84,13 @@ void SettingsWidget::setupUi() {
6584
auto* buttonLayout = new QHBoxLayout();
6685
buttonLayout->addStretch();
6786

68-
m_revertButton = new QPushButton("Revert", this);
87+
m_revertButton = new QPushButton("Revert", contentWidget);
6988
m_revertButton->setMinimumWidth(100);
7089
m_revertButton->setEnabled(false);
7190
connect(m_revertButton, &QPushButton::clicked, this, &SettingsWidget::onRevertClicked);
7291
buttonLayout->addWidget(m_revertButton);
7392

74-
m_applyButton = new QPushButton("Apply", this);
93+
m_applyButton = new QPushButton("Apply", contentWidget);
7594
m_applyButton->setMinimumWidth(100);
7695
m_applyButton->setEnabled(false);
7796
connect(m_applyButton, &QPushButton::clicked, this, &SettingsWidget::onApplyClicked);
@@ -82,7 +101,13 @@ void SettingsWidget::setupUi() {
82101
// Add stretch at the bottom
83102
mainLayout->addStretch();
84103

85-
setLayout(mainLayout);
104+
// Set the content widget to the scroll area
105+
scrollArea->setWidget(contentWidget);
106+
107+
// Add scroll area to the outer layout
108+
outerLayout->addWidget(scrollArea);
109+
110+
setLayout(outerLayout);
86111
}
87112

88113
void SettingsWidget::createRepositorySettings() {
@@ -258,6 +283,39 @@ void SettingsWidget::createMaintenanceSettings() {
258283
lockInfoLabel->setStyleSheet("QLabel { color: #888; font-size: 11px; margin-top: 5px; margin-left: 10px; }");
259284
maintenanceLayout->addWidget(lockInfoLabel);
260285

286+
// Spacer
287+
maintenanceLayout->addSpacing(15);
288+
289+
// Sync repositories section
290+
auto* syncReposLayout = new QHBoxLayout();
291+
292+
auto* syncReposLabel = new QLabel(
293+
"Synchronize Repositories:",
294+
this);
295+
syncReposLabel->setStyleSheet("QLabel { font-weight: bold; }");
296+
syncReposLayout->addWidget(syncReposLabel);
297+
298+
syncReposLayout->addStretch();
299+
300+
m_syncReposButton = new QPushButton("Sync Repositories", this);
301+
m_syncReposButton->setMinimumWidth(150);
302+
m_syncReposButton->setToolTip(
303+
"Manually synchronize package databases (pacman -Sy).\n"
304+
"This updates the list of available packages from all enabled repositories.");
305+
connect(m_syncReposButton, &QPushButton::clicked, this, &SettingsWidget::onSyncReposClicked);
306+
syncReposLayout->addWidget(m_syncReposButton);
307+
308+
maintenanceLayout->addLayout(syncReposLayout);
309+
310+
// Sync info
311+
auto* syncInfoLabel = new QLabel(
312+
"Use this to manually update your package database. This is useful after enabling/disabling repositories\n"
313+
"or when you want to ensure you have the latest package information.",
314+
this);
315+
syncInfoLabel->setWordWrap(true);
316+
syncInfoLabel->setStyleSheet("QLabel { color: #888; font-size: 11px; margin-top: 5px; margin-left: 10px; }");
317+
maintenanceLayout->addWidget(syncInfoLabel);
318+
261319
m_maintenanceGroup->setLayout(maintenanceLayout);
262320
}
263321

@@ -969,3 +1027,59 @@ void SettingsWidget::onRemoveChaoticClicked() {
9691027
process->start("pkexec", QStringList() << "pacman" << "-Rns" << "--noconfirm"
9701028
<< "chaotic-keyring" << "chaotic-mirrorlist");
9711029
}
1030+
1031+
void SettingsWidget::onSyncReposClicked() {
1032+
QMessageBox msgBox(this);
1033+
msgBox.setIcon(QMessageBox::Question);
1034+
msgBox.setWindowTitle("Sync Repositories");
1035+
msgBox.setText("Synchronize package databases?");
1036+
msgBox.setInformativeText(
1037+
"This will run: pacman -Sy\n\n"
1038+
"This updates the list of available packages from all enabled repositories.\n"
1039+
"This is useful after enabling/disabling repositories or when you want to "
1040+
"ensure you have the latest package information.");
1041+
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
1042+
msgBox.setDefaultButton(QMessageBox::Yes);
1043+
1044+
if (msgBox.exec() != QMessageBox::Yes) {
1045+
return;
1046+
}
1047+
1048+
m_statusLabel->setText("Synchronizing repositories...");
1049+
m_statusLabel->setStyleSheet("QLabel { color: #0066cc; padding: 10px; }");
1050+
m_statusLabel->show();
1051+
m_syncReposButton->setEnabled(false);
1052+
1053+
// Run pacman -Sy with pkexec
1054+
QProcess* process = new QProcess(this);
1055+
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
1056+
this, [this, process](int exitCode, QProcess::ExitStatus exitStatus) {
1057+
process->deleteLater();
1058+
m_syncReposButton->setEnabled(true);
1059+
1060+
if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
1061+
m_statusLabel->setText("Repositories synchronized successfully!");
1062+
m_statusLabel->setStyleSheet("QLabel { color: #00aa00; padding: 10px; font-weight: bold; }");
1063+
m_statusLabel->show();
1064+
Logger::info("Repositories synchronized successfully");
1065+
1066+
// Refresh ALPM databases
1067+
AlpmWrapper::instance().refreshDatabases();
1068+
1069+
QMessageBox::information(this, "Success",
1070+
"Package databases synchronized successfully!\n\n"
1071+
"The package list has been updated with the latest available packages.");
1072+
} else {
1073+
m_statusLabel->setText("Failed to synchronize repositories.");
1074+
m_statusLabel->setStyleSheet("QLabel { color: #aa0000; padding: 10px; }");
1075+
m_statusLabel->show();
1076+
Logger::error("Failed to synchronize repositories");
1077+
1078+
QMessageBox::critical(this, "Error",
1079+
"Failed to synchronize package databases.\n"
1080+
"Please check your internet connection and try again.");
1081+
}
1082+
});
1083+
1084+
process->start("pkexec", QStringList() << "pacman" << "-Sy");
1085+
}

src/gui/settings_widget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SettingsWidget : public QWidget {
5151
// Maintenance settings
5252
QGroupBox* m_maintenanceGroup;
5353
QPushButton* m_removeLockButton;
54+
QPushButton* m_syncReposButton;
5455

5556
// Control buttons
5657
QPushButton* m_applyButton;
@@ -70,6 +71,7 @@ private slots:
7071
void onSetupChaoticClicked();
7172
void onRemoveChaoticClicked();
7273
void onRemoveLockClicked();
74+
void onSyncReposClicked();
7375
};
7476

7577
#endif // SETTINGS_WIDGET_H

0 commit comments

Comments
 (0)