1 /*
2     KSambaLog, a samba log viewer tool
3     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "sambaFactory.h"
9 
10 #include <KLocalizedString>
11 
12 #include "ksystemlog_debug.h"
13 #include "logMode.h"
14 #include "multipleActions.h"
15 
16 #include "netbiosLogMode.h"
17 #include "sambaAccessLogMode.h"
18 #include "sambaLogMode.h"
19 
20 #include "sambaConfiguration.h"
21 #include "sambaConfigurationWidget.h"
22 #include "sambaItemBuilder.h"
23 
createLogModes() const24 QList<LogMode *> SambaLogModeFactory::createLogModes() const
25 {
26     // Create the shared configuration and configuration widget between the logModes
27     QSharedPointer<SambaConfiguration> configuration = QSharedPointer<SambaConfiguration>(new SambaConfiguration());
28     auto configurationWidget = new SambaConfigurationWidget();
29 
30     QList<LogMode *> logModes;
31     logModes.append(new SambaLogMode(configuration, configurationWidget, new SambaItemBuilder()));
32     logModes.append(new SambaAccessLogMode(configuration, configurationWidget, new SambaItemBuilder()));
33     logModes.append(new NetbiosLogMode(configuration, configurationWidget, new SambaItemBuilder()));
34 
35     return logModes;
36 }
37 
createLogModeAction() const38 LogModeAction *SambaLogModeFactory::createLogModeAction() const
39 {
40     LogMode *sambaLogMode = Globals::instance().findLogMode(QStringLiteral(SAMBA_LOG_MODE_ID));
41     LogMode *sambaAccessLogMode = Globals::instance().findLogMode(QStringLiteral(SAMBA_ACCESS_LOG_MODE_ID));
42     LogMode *sambaNetbiosLogMode = Globals::instance().findLogMode(QStringLiteral(NETBIOS_LOG_MODE_ID));
43 
44     const bool sambaLogsExist = sambaLogMode->filesExist();
45     const bool sambaAccessLogsExist = sambaAccessLogMode->filesExist();
46     const bool sambaNetbiosLogsExist = sambaNetbiosLogMode->filesExist();
47 
48     if (!sambaLogsExist && !sambaAccessLogsExist && !sambaNetbiosLogsExist) {
49         return nullptr;
50     }
51 
52     auto multipleActions = new MultipleActions(QIcon::fromTheme(QStringLiteral(SAMBA_MODE_ICON)), i18n("Samba"), sambaLogMode);
53 
54     if (sambaLogsExist) {
55         multipleActions->addInnerAction(sambaLogMode->action());
56     }
57 
58     if (sambaAccessLogsExist) {
59         multipleActions->addInnerAction(sambaAccessLogMode->action());
60     }
61 
62     if (sambaNetbiosLogsExist) {
63         multipleActions->addInnerAction(sambaNetbiosLogMode->action());
64     }
65 
66     multipleActions->setCategory(LogModeAction::ServicesCategory);
67 
68     return multipleActions;
69 }
70