@@ -88,9 +88,9 @@ void MainWindow::checkHideToolsInMenu()
8888
8989void MainWindow::initializeCategoryLists ()
9090{
91- const QString search_folder {" /usr/share/applications" };
91+ const QString searchFolder {" /usr/share/applications" };
9292 for (auto it = categories.cbegin (); it != categories.cend (); ++it) {
93- *(it.value ()) = listDesktopFiles (it.key (), search_folder );
93+ *(it.value ()) = listDesktopFiles (it.key (), searchFolder );
9494 }
9595}
9696
@@ -146,7 +146,7 @@ void MainWindow::restoreWindowGeometry()
146146}
147147
148148// List .desktop files that contain a specific string
149- QStringList MainWindow::listDesktopFiles (const QString &search_string , const QString &location)
149+ QStringList MainWindow::listDesktopFiles (const QString &searchString , const QString &location)
150150{
151151 QDirIterator it (location, {" *.desktop" }, QDir::Files, QDirIterator::Subdirectories);
152152 QStringList matchingFiles;
@@ -156,36 +156,36 @@ QStringList MainWindow::listDesktopFiles(const QString &search_string, const QSt
156156 if (file.open (QIODevice::ReadOnly | QIODevice::Text)) {
157157 QTextStream in (&file);
158158 QString content = in.readAll ();
159- if (content.contains (search_string )) {
159+ if (content.contains (searchString )) {
160160 matchingFiles << file.fileName ();
161161 }
162162 }
163163 }
164164 return matchingFiles;
165165}
166166
167- // Load info (name, comment, exec, icon_name , category, terminal) to the info_map
167+ // Load info (name, comment, exec, iconName , category, terminal) to the info_map
168168void MainWindow::readInfo (const QMultiMap<QString, QStringList> &category_map)
169169{
170170 const QString lang = QLocale ().name ().split (' _' ).first ();
171- const QString lang_region = QLocale ().name ();
171+ const QString langRegion = QLocale ().name ();
172172
173173 for (auto it = category_map.cbegin (); it != category_map.cend (); ++it) {
174174 const QString category = it.key ();
175175 const QStringList &fileList = it.value ();
176176
177177 QMultiMap<QString, QStringList> categoryInfoMap;
178- for (const QString &file_name : fileList) {
179- QFile file (file_name );
178+ for (const QString &fileName : fileList) {
179+ QFile file (fileName );
180180 if (!file.open (QFile::Text | QFile::ReadOnly)) {
181181 continue ;
182182 }
183183 QTextStream stream (&file);
184184 QString text = stream.readAll ();
185185 file.close ();
186186
187- QString name = lang != " en" ? getTranslation (text, " Name" , lang_region , lang) : QString ();
188- QString comment = lang != " en" ? getTranslation (text, " Comment" , lang_region , lang) : QString ();
187+ QString name = lang != " en" ? getTranslation (text, " Name" , langRegion , lang) : QString ();
188+ QString comment = lang != " en" ? getTranslation (text, " Comment" , langRegion , lang) : QString ();
189189
190190 name = name.isEmpty () ? getValueFromText (text, " Name" ).remove (QRegularExpression (" ^MX " )).replace (' &' , " &&" )
191191 : name;
@@ -194,19 +194,19 @@ void MainWindow::readInfo(const QMultiMap<QString, QStringList> &category_map)
194194 QString exec = getValueFromText (text, " Exec" );
195195 fixExecItem (&exec);
196196
197- QString icon_name = getValueFromText (text, " Icon" );
198- QString terminal_switch = getValueFromText (text, " Terminal" );
197+ QString iconName = getValueFromText (text, " Icon" );
198+ QString terminalSwitch = getValueFromText (text, " Terminal" );
199199
200- categoryInfoMap.insert (file_name , {name, comment, icon_name , exec, category, terminal_switch });
200+ categoryInfoMap.insert (fileName , {name, comment, iconName , exec, category, terminalSwitch });
201201 }
202202 info_map.insert (category, categoryInfoMap);
203203 }
204204}
205205
206- QString MainWindow::getTranslation (const QString &text, const QString &key, const QString &lang_region ,
206+ QString MainWindow::getTranslation (const QString &text, const QString &key, const QString &langRegion ,
207207 const QString &lang)
208208{
209- QRegularExpression re (' ^' + key + " \\ [" + lang_region + " \\ ]=(.*)$" );
209+ QRegularExpression re (' ^' + key + " \\ [" + langRegion + " \\ ]=(.*)$" );
210210 re.setPatternOptions (QRegularExpression::MultilineOption);
211211 QString translation = re.match (text).captured (1 ).trimmed ();
212212 if (!translation.isEmpty ()) {
@@ -245,16 +245,16 @@ void MainWindow::addButtons(const QMultiMap<QString, QMultiMap<QString, QStringL
245245 QString name;
246246 QString comment;
247247 QString exec;
248- QString icon_name ;
248+ QString iconName ;
249249 QString terminal_switch;
250250
251251 // Get max button size
252252 QMapIterator<QString, QStringList> itsize (info_map.value (category));
253253 int max_button_width = 20 ; // set a min != 0 to avoid div/0 in case of error
254254 while (itsize.hasNext ()) {
255- QString file_name = itsize.next ().key ();
256- QStringList file_info = info_map.value (category).value (file_name );
257- name = file_info .at (Info::Name);
255+ QString fileName = itsize.next ().key ();
256+ QStringList fileInfo = info_map.value (category).value (fileName );
257+ name = fileInfo .at (Info::Name);
258258 max_button_width = qMax (name.size () * QApplication::font ().pointSize () + icon_size, max_button_width);
259259 }
260260 max = width () / max_button_width;
@@ -284,20 +284,20 @@ void MainWindow::addButtons(const QMultiMap<QString, QMultiMap<QString, QStringL
284284 col = 0 ;
285285 QMapIterator<QString, QStringList> it (info_map.value (category));
286286 while (it.hasNext ()) {
287- QString file_name = it.next ().key ();
287+ QString fileName = it.next ().key ();
288288 if (col >= col_count) {
289289 col_count = col + 1 ;
290290 }
291- QStringList file_info = info_map.value (category).value (file_name );
292- name = file_info .at (Info::Name);
293- comment = file_info .at (Info::Comment);
294- icon_name = file_info .at (Info::IconName);
295- exec = file_info .at (Info::Exec);
296- terminal_switch = file_info .at (Info::Terminal);
291+ QStringList fileInfo = info_map.value (category).value (fileName );
292+ name = fileInfo .at (Info::Name);
293+ comment = fileInfo .at (Info::Comment);
294+ iconName = fileInfo .at (Info::IconName);
295+ exec = fileInfo .at (Info::Exec);
296+ terminal_switch = fileInfo .at (Info::Terminal);
297297 btn = new FlatButton (name);
298298 btn->setToolTip (comment);
299299 btn->setAutoDefault (false );
300- btn->setIcon (findIcon (icon_name ));
300+ btn->setIcon (findIcon (iconName ));
301301 btn->setIconSize (icon_size, icon_size);
302302 ui->gridLayout_btn ->addWidget (btn, row, col);
303303 // ui->gridLayout_btn->setRowStretch(row, 0);
@@ -315,12 +315,12 @@ void MainWindow::addButtons(const QMultiMap<QString, QMultiMap<QString, QStringL
315315 ui->gridLayout_btn ->setRowStretch (row + 2 , 1 );
316316}
317317
318- QIcon MainWindow::findIcon (const QString &icon_name )
318+ QIcon MainWindow::findIcon (const QString &iconName )
319319{
320320 static QIcon defaultIcon;
321321 static bool defaultIconLoaded = false ;
322322
323- if (icon_name .isEmpty ()) {
323+ if (iconName .isEmpty ()) {
324324 if (!defaultIconLoaded) {
325325 defaultIcon = findIcon (" utilities-terminal" );
326326 defaultIconLoaded = true ;
@@ -329,51 +329,51 @@ QIcon MainWindow::findIcon(const QString &icon_name)
329329 }
330330
331331 // Check if the icon name is an absolute path and exists
332- if (QFileInfo (icon_name ).isAbsolute () && QFile::exists (icon_name )) {
333- return QIcon (icon_name );
332+ if (QFileInfo (iconName ).isAbsolute () && QFile::exists (iconName )) {
333+ return QIcon (iconName );
334334 }
335335
336336 // Prepare regular expression to strip extension
337337 static const QRegularExpression re (R"( \.(png|svg|xpm)$)" );
338- QString name_noext = icon_name ;
339- name_noext .remove (re);
338+ QString nameNoExt = iconName ;
339+ nameNoExt .remove (re);
340340
341341 // Return the themed icon if available
342- if (QIcon::hasThemeIcon (name_noext )) {
343- return QIcon::fromTheme (name_noext );
342+ if (QIcon::hasThemeIcon (nameNoExt )) {
343+ return QIcon::fromTheme (nameNoExt );
344344 }
345345
346346 // Define common search paths for icons
347- QStringList search_paths {QDir::homePath () + " /.local/share/icons/" ,
348- " /usr/share/pixmaps/" ,
349- " /usr/local/share/icons/" ,
350- " /usr/share/icons/" ,
351- " /usr/share/icons/hicolor/scalable/apps/" ,
352- " /usr/share/icons/hicolor/48x48/apps/" ,
353- " /usr/share/icons/Adwaita/48x48/legacy/" };
347+ QStringList searchPaths {QDir::homePath () + " /.local/share/icons/" ,
348+ " /usr/share/pixmaps/" ,
349+ " /usr/local/share/icons/" ,
350+ " /usr/share/icons/" ,
351+ " /usr/share/icons/hicolor/scalable/apps/" ,
352+ " /usr/share/icons/hicolor/48x48/apps/" ,
353+ " /usr/share/icons/Adwaita/48x48/legacy/" };
354354
355- // Optimization: search first for the full icon_name with the specified extension
356- auto it = std::find_if (search_paths .cbegin (), search_paths .cend (),
357- [&](const QString &path) { return QFile::exists (path + icon_name ); });
358- if (it != search_paths .cend ()) {
359- return QIcon (*it + icon_name );
355+ // Optimization: search first for the full iconName with the specified extension
356+ auto it = std::find_if (searchPaths .cbegin (), searchPaths .cend (),
357+ [&](const QString &path) { return QFile::exists (path + iconName ); });
358+ if (it != searchPaths .cend ()) {
359+ return QIcon (*it + iconName );
360360 }
361361
362362 // Search for the icon without extension in the specified paths
363- for (const QString &path : search_paths ) {
363+ for (const QString &path : searchPaths ) {
364364 if (!QFile::exists (path)) {
365365 continue ;
366366 }
367367 for (const char *ext : {" .png" , " .svg" , " .xpm" }) {
368- QString file = path + name_noext + ext;
368+ QString file = path + nameNoExt + ext;
369369 if (QFile::exists (file)) {
370370 return QIcon (file);
371371 }
372372 }
373373 }
374374
375375 // If the icon is "utilities-terminal" and not found, return the default icon if it's already loaded
376- if (icon_name == " utilities-terminal" ) {
376+ if (iconName == " utilities-terminal" ) {
377377 if (!defaultIconLoaded) {
378378 defaultIcon = QIcon ();
379379 defaultIconLoaded = true ;
@@ -408,11 +408,11 @@ void MainWindow::resizeEvent(QResizeEvent *event)
408408 if (event->oldSize ().width () == event->size ().width ()) {
409409 return ;
410410 }
411- int new_count = width () / 200 ;
412- if (new_count == col_count || (new_count > max_elements && col_count == max_elements)) {
411+ int newCount = width () / 200 ;
412+ if (newCount == col_count || (newCount > max_elements && col_count == max_elements)) {
413413 return ;
414414 }
415- col_count = new_count ;
415+ col_count = newCount ;
416416
417417 if (ui->textSearch ->text ().isEmpty ()) {
418418 addButtons (info_map);
@@ -425,8 +425,8 @@ void MainWindow::resizeEvent(QResizeEvent *event)
425425void MainWindow::checkHide_clicked (bool checked)
426426{
427427 for (const QStringList &list : qAsConst (category_map)) {
428- for (const QString &file_name : qAsConst (list)) {
429- hideShowIcon (file_name , checked);
428+ for (const QString &fileName : qAsConst (list)) {
429+ hideShowIcon (fileName , checked);
430430 }
431431 }
432432 QProcess process;
@@ -438,22 +438,22 @@ void MainWindow::checkHide_clicked(bool checked)
438438}
439439
440440// Hide or show icon for .desktop file
441- void MainWindow::hideShowIcon (const QString &file_name , bool hide)
441+ void MainWindow::hideShowIcon (const QString &fileName , bool hide)
442442{
443- QFileInfo file (file_name );
443+ QFileInfo file (fileName );
444444 const QDir userApplicationsDir (QDir::homePath () + " /.local/share/applications" );
445445 if (!userApplicationsDir.exists () && !QDir ().mkpath (userApplicationsDir.absolutePath ())) {
446446 qWarning () << " Failed to create directory:" << userApplicationsDir.absolutePath ();
447447 return ;
448448 }
449449
450- const QString file_name_home = userApplicationsDir.filePath (file.fileName ());
450+ const QString fileNameLocal = userApplicationsDir.filePath (file.fileName ());
451451 if (!hide) {
452- QFile::remove (file_name_home );
452+ QFile::remove (fileNameLocal );
453453 } else {
454- QFile::copy (file_name, file_name_home );
454+ QFile::copy (fileName, fileNameLocal );
455455 QProcess process;
456- process.start (" sed" , {" -ire" , " /^(NoDisplay|Hidden)=/d" , " -e" , " /Exec/aNoDisplay=true" , file_name_home });
456+ process.start (" sed" , {" -ire" , " /^(NoDisplay|Hidden)=/d" , " -e" , " /Exec/aNoDisplay=true" , fileNameLocal });
457457 process.waitForFinished ();
458458 }
459459}
@@ -553,8 +553,7 @@ void MainWindow::removeEnvExclusive(QStringList *list, const QStringList &termsT
553553// Remove all items from the layout
554554void MainWindow::clearGrid ()
555555{
556- QLayoutItem *child {nullptr };
557- while ((child = ui->gridLayout_btn ->takeAt (0 )) != nullptr ) {
556+ while (auto *child = ui->gridLayout_btn ->takeAt (0 )) {
558557 delete child->widget ();
559558 delete child;
560559 }
0 commit comments