Changeset View
Changeset View
Standalone View
Standalone View
src/appchooserdialog.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 42 | { | |||
---|---|---|---|---|---|
60 | vboxLayout->addWidget(label); | 60 | vboxLayout->addWidget(label); | ||
61 | 61 | | |||
62 | m_gridLayout = new QGridLayout(); | 62 | m_gridLayout = new QGridLayout(); | ||
63 | 63 | | |||
64 | addDialogItems(); | 64 | addDialogItems(); | ||
65 | 65 | | |||
66 | vboxLayout->addLayout(m_gridLayout); | 66 | vboxLayout->addLayout(m_gridLayout); | ||
67 | 67 | | |||
68 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this); | 68 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Open, this); | ||
69 | connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | 69 | connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | ||
70 | connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); | ||||
70 | 71 | | |||
71 | vboxLayout->addWidget(buttonBox, 0, Qt::AlignBottom | Qt::AlignRight); | 72 | vboxLayout->addWidget(buttonBox, 0, Qt::AlignBottom | Qt::AlignRight); | ||
72 | 73 | | |||
73 | setLayout(vboxLayout); | 74 | setLayout(vboxLayout); | ||
74 | setWindowTitle(i18n("Open with")); | 75 | setWindowTitle(i18n("Open with")); | ||
75 | } | 76 | } | ||
76 | 77 | | |||
77 | AppChooserDialog::~AppChooserDialog() | 78 | AppChooserDialog::~AppChooserDialog() | ||
Show All 40 Lines | 104 | if (changed) { | |||
118 | } | 119 | } | ||
119 | 120 | | |||
120 | addDialogItems(); | 121 | addDialogItems(); | ||
121 | } | 122 | } | ||
122 | } | 123 | } | ||
123 | 124 | | |||
124 | QString AppChooserDialog::selectedApplication() const | 125 | QString AppChooserDialog::selectedApplication() const | ||
125 | { | 126 | { | ||
127 | if (m_selectedApplication.isEmpty()) { | ||||
128 | return m_defaultApp; | ||||
129 | } | ||||
130 | | ||||
126 | return m_selectedApplication; | 131 | return m_selectedApplication; | ||
127 | } | 132 | } | ||
128 | 133 | | |||
129 | void AppChooserDialog::addDialogItems() | 134 | void AppChooserDialog::addDialogItems() | ||
130 | { | 135 | { | ||
131 | int i = 0, j = 0; | 136 | int i = 0, j = 0; | ||
132 | for (const QString &choice : m_choices) { | 137 | for (const QString &choice : m_choices) { | ||
133 | const QString desktopFile = choice + QStringLiteral(".desktop"); | 138 | const QString desktopFile = choice + QStringLiteral(".desktop"); | ||
134 | const QStringList desktopFilesLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile); | 139 | const QStringList desktopFilesLocations = QStandardPaths::locateAll(QStandardPaths::ApplicationsLocation, desktopFile, QStandardPaths::LocateFile); | ||
135 | for (const QString &desktopFile : desktopFilesLocations) { | 140 | for (const QString &desktopFile : desktopFilesLocations) { | ||
136 | QString applicationIcon; | 141 | QString applicationIcon; | ||
137 | QString applicationName; | 142 | QString applicationName; | ||
138 | QSettings settings(desktopFile, QSettings::IniFormat); | 143 | QSettings settings(desktopFile, QSettings::IniFormat); | ||
139 | settings.beginGroup(QStringLiteral("Desktop Entry")); | 144 | settings.beginGroup(QStringLiteral("Desktop Entry")); | ||
140 | if (settings.contains(QStringLiteral("X-GNOME-FullName"))) { | 145 | if (settings.contains(QStringLiteral("X-GNOME-FullName"))) { | ||
141 | applicationName = settings.value(QStringLiteral("X-GNOME-FullName")).toString(); | 146 | applicationName = settings.value(QStringLiteral("X-GNOME-FullName")).toString(); | ||
142 | } else { | 147 | } else { | ||
143 | applicationName = settings.value(QStringLiteral("Name")).toString(); | 148 | applicationName = settings.value(QStringLiteral("Name")).toString(); | ||
144 | } | 149 | } | ||
145 | applicationIcon = settings.value(QStringLiteral("Icon")).toString(); | 150 | applicationIcon = settings.value(QStringLiteral("Icon")).toString(); | ||
146 | 151 | | |||
147 | AppChooserDialogItem *item = new AppChooserDialogItem(applicationName, applicationIcon, choice, this); | 152 | AppChooserDialogItem *item = new AppChooserDialogItem(applicationName, applicationIcon, choice, this); | ||
148 | m_gridLayout->addWidget(item, i, j++, Qt::AlignHCenter); | 153 | m_gridLayout->addWidget(item, i, j++, Qt::AlignHCenter); | ||
149 | 154 | | |||
155 | connect(item, &AppChooserDialogItem::clicked, this, [this] (const QString &selectedApplication) { | ||||
156 | m_selectedApplication = selectedApplication; | ||||
157 | }); | ||||
150 | connect(item, &AppChooserDialogItem::doubleClicked, this, [this] (const QString &selectedApplication) { | 158 | connect(item, &AppChooserDialogItem::doubleClicked, this, [this] (const QString &selectedApplication) { | ||
151 | m_selectedApplication = selectedApplication; | 159 | m_selectedApplication = selectedApplication; | ||
152 | QDialog::accept(); | 160 | QDialog::accept(); | ||
153 | }); | 161 | }); | ||
154 | 162 | | |||
155 | if (choice == m_defaultApp) { | 163 | if (choice == m_defaultApp) { | ||
156 | item->setDown(true); | 164 | item->setDown(true); | ||
157 | item->setChecked(true); | 165 | item->setChecked(true); | ||
Show All 9 Lines |