File indexing completed on 2024-04-28 09:41:05

0001 /*
0002     KT icons implementation.
0003     --------------------------------------------------------------------
0004     SPDX-FileCopyrightText: 1999 Gary Meyer <gary@meyer.net>
0005     --------------------------------------------------------------------
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #include "kcronHelper.h"
0010 
0011 #include <QComboBox>
0012 #include <QFontMetrics>
0013 #include <QTextEdit>
0014 
0015 #include "ctcron.h"
0016 #include "cthost.h"
0017 
0018 #include "crontabWidget.h"
0019 
0020 void KCronHelper::initUserCombo(QComboBox *userCombo, CrontabWidget *crontabWidget, const QString &selectedUserLogin)
0021 {
0022     // This only applies to the System Crontab.
0023     // Populate the "Run as:" combobox with the login names of all current crons,
0024     // selecting the current user (root) as the default selection.
0025     int userComboIndex = 0;
0026 
0027     QStringList users;
0028     int selectedIndex = 0;
0029     const auto crons = crontabWidget->ctHost()->mCrons;
0030     for (CTCron *ctCron : crons) {
0031         users.append(ctCron->userLogin());
0032 
0033         if (ctCron->userLogin() == selectedUserLogin) {
0034             selectedIndex = userComboIndex;
0035         }
0036 
0037         userComboIndex++;
0038     }
0039 
0040     users.sort();
0041 
0042     userCombo->addItems(users);
0043     userCombo->setCurrentIndex(selectedIndex);
0044 }
0045 
0046 QTextEdit *KCronHelper::createCommentEdit(QWidget *parent)
0047 {
0048     auto edit = new QTextEdit(parent);
0049     edit->setAcceptRichText(false);
0050     edit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
0051     edit->setTabChangesFocus(true);
0052 
0053     const QFontMetrics fontMetrics(edit->currentFont());
0054     edit->setMaximumHeight(fontMetrics.lineSpacing() * 3); // TODO Choose a smarter value
0055 
0056     return edit;
0057 }