1 /*
2  * Copyright (c) 2017-2018 Nitrokey UG
3  *
4  * This file is part of Nitrokey App.
5  *
6  * Nitrokey App is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * any later version.
10  *
11  * Nitrokey App is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Nitrokey App. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * SPDX-License-Identifier: GPL-3.0
20  */
21 
22 #ifndef NITROKEYAPP_STORAGEACTIONS_H
23 #define NITROKEYAPP_STORAGEACTIONS_H
24 #include <QObject>
25 #include "src/GUI/Authentication.h"
26 #include "src/ui/nitrokey-applet.h"
27 #include <functional>
28 
29 class StorageActions: public QObject {
30 Q_OBJECT
31 
32 private:
33   Q_DISABLE_COPY(StorageActions);
34 
35   Authentication * auth_admin;
36   Authentication * auth_user;
37   bool CryptedVolumeActive = false;
38   bool HiddenVolumeActive = false;
39   void _execute_SD_clearing(const std::string &s);
40   std::function<void(QString)> startProgressFunc;
41   std::function<void()> end_progress_function;
42   std::function<void(QString)> show_message_function;
43   void runAndHandleErrorsInUI(QString successMessage, QString operationFailureMessage,
44                               std::function<void(void)> codeToRunInDeviceThread,
45                               std::function<void(void)> onSuccessInGuiThread);
46 private slots:
47   void on_StorageStatusChanged();
48 
49 public:
50   StorageActions(QObject *parent, Authentication *auth_admin, Authentication *auth_user);
51   void set_start_progress_window(std::function<void(QString)> _start_progress_function);
52   void set_end_progress_window(std::function<void()> _end_progress_function);
53   void set_show_message(std::function<void(QString)> _show_message);
54 
55 public slots:
56   void startStick20DestroyCryptedVolume(int fillSDWithRandomChars);
57   void startStick20FillSDCardWithRandomChars();
58   void startStick20EnableCryptedVolume();
59   void startStick20DisableCryptedVolume();
60   void startStick20EnableHiddenVolume();
61   void startStick20DisableHiddenVolume();
62   void startLockDeviceAction(bool ask_for_confirmation = true);
63   void startStick20SetReadOnlyUncryptedVolume();
64   void startStick20SetReadWriteUncryptedVolume();
65   void startStick20LockStickHardware();
66   void startStick20EnableFirmwareUpdate();
67   void startStick20ExportFirmwareToFile();
68 
69   void startStick20ClearNewSdCardFound();
70   void startStick20SetupHiddenVolume();
71   void startStick20SetReadOnlyEncryptedVolume();
72   void startStick20SetReadWriteEncryptedVolume();
73 
74 signals:
75   void storageStatusChanged();
76   void storageStatusUpdated();
77   void longOperationStarted();
78   void FactoryReset();
79 
80 
81 };
82 
83 
84 #endif //NITROKEYAPP_STORAGEACTIONS_H
85