File indexing completed on 2024-05-19 05:49:13
0001 /* 0002 KApacheLog, a apache log viewer tool 0003 SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "authenticationConfigurationWidget.h" 0009 0010 AuthenticationConfigurationWidget::AuthenticationConfigurationWidget() 0011 : LogModeConfigurationWidget(i18n("Authentication Log"), QStringLiteral(AUTHENTICATION_MODE_ICON), i18n("Authentication Log")) 0012 { 0013 auto layout = new QVBoxLayout(this); 0014 0015 mWarningBox = new KMessageWidget(this); 0016 mWarningBox->setVisible(false); 0017 mWarningBox->setMessageType(KMessageWidget::Warning); 0018 mWarningBox->setText(i18n("Log file does not exist. Mode will be unavailable.")); 0019 mWarningBox->setCloseButtonVisible(false); 0020 mWarningBox->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning"))); 0021 0022 // Authentication log file 0023 auto authenticationBox = new QGroupBox(i18n("Authentication Log File")); 0024 auto authenticationLayout = new QVBoxLayout(); 0025 auto filePathLayout = new QHBoxLayout(); 0026 authenticationBox->setLayout(authenticationLayout); 0027 0028 authenticationLayout->addWidget(mWarningBox); 0029 authenticationLayout->addLayout(filePathLayout); 0030 0031 layout->addWidget(authenticationBox); 0032 0033 filePathLayout->addWidget(new QLabel(i18n("Authentication log file:"))); 0034 0035 mAuthenticationUrlRequester = new KUrlRequester(authenticationBox); 0036 mAuthenticationUrlRequester->setMode(KFile::File); 0037 0038 mAuthenticationUrlRequester->setToolTip(i18n("You can type or choose the authentication log file (example: <i>/var/log/auth.log</i>).")); 0039 mAuthenticationUrlRequester->setWhatsThis( 0040 i18n("You can type or choose here the authentication log file. This file will be analyzed when you " 0041 "select the <b>Authentication log</b> menu. Generally, its name is <i>/var/log/auth.log</i>")); 0042 filePathLayout->addWidget(mAuthenticationUrlRequester); 0043 0044 connect(mAuthenticationUrlRequester, &KUrlRequester::textChanged, this, &LogModeConfigurationWidget::configurationChanged); 0045 0046 layout->addStretch(); 0047 } 0048 0049 void AuthenticationConfigurationWidget::saveConfig() 0050 { 0051 auto *authenticationConfiguration = 0052 Globals::instance().findLogMode(QStringLiteral(AUTHENTICATION_LOG_MODE_ID))->logModeConfiguration<AuthenticationConfiguration *>(); 0053 0054 authenticationConfiguration->setAuthenticationPath(mAuthenticationUrlRequester->url().toLocalFile()); 0055 } 0056 0057 void AuthenticationConfigurationWidget::readConfig() 0058 { 0059 auto *authenticationConfiguration = 0060 Globals::instance().findLogMode(QStringLiteral(AUTHENTICATION_LOG_MODE_ID))->logModeConfiguration<AuthenticationConfiguration *>(); 0061 0062 const QString path = authenticationConfiguration->authenticationPath(); 0063 const QFileInfo fileInfo(path); 0064 mWarningBox->setVisible(!fileInfo.exists()); 0065 0066 mAuthenticationUrlRequester->setUrl(QUrl::fromLocalFile(path)); 0067 } 0068 0069 void AuthenticationConfigurationWidget::defaultConfig() 0070 { 0071 // TODO Find a way to read the configuration per default 0072 readConfig(); 0073 } 0074 0075 bool AuthenticationConfigurationWidget::isValid() const 0076 { 0077 if (!mAuthenticationUrlRequester->url().toLocalFile().isEmpty()) { 0078 return true; 0079 } 0080 0081 return false; 0082 } 0083 0084 #include "moc_authenticationConfigurationWidget.cpp"