ORE Studio 0.0.4
Loading...
Searching...
No Matches
AddItemDialog.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_ADD_ITEM_DIALOG_HPP
21#define ORES_QT_ADD_ITEM_DIALOG_HPP
22
23#include <QWidget>
24#include <QToolBar>
25#include <QAction>
26#include <QComboBox>
27#include <QLineEdit>
28#include <QSpinBox>
29#include <QTextEdit>
30#include <QCheckBox>
31#include <QLabel>
32#include <optional>
33#include <boost/uuid/uuid.hpp>
34#include "ores.connections/domain/folder.hpp"
35#include "ores.connections/domain/environment.hpp"
36#include "ores.connections/domain/connection.hpp"
37#include "ores.connections/domain/tag.hpp"
38#include "ores.logging/make_logger.hpp"
39#include "ores.qt/ConnectionTypes.hpp"
40
41namespace ores::qt {
42class TagSelectorWidget;
43}
44
45namespace ores::connections::service {
46class connection_manager;
47}
48
49namespace ores::qt {
50
54enum class ItemType {
55 Folder,
56 Environment,
57 Connection
58};
59
67class AddItemDialog : public QWidget {
68 Q_OBJECT
69
70private:
71 inline static std::string_view logger_name = "ores.qt.add_item_dialog";
72
73 [[nodiscard]] static auto& lg() {
74 using namespace ores::logging;
75 static auto instance = make_logger(logger_name);
76 return instance;
77 }
78
79public:
80 explicit AddItemDialog(
82 QWidget* parent = nullptr);
83 ~AddItemDialog() override;
84
85 void setItemType(ItemType type);
86 ItemType itemType() const { return itemType_; }
87
88 void setCreateMode(bool createMode);
89 bool isCreateMode() const { return isCreateMode_; }
90
91 // Folder operations
92 void setFolder(const connections::domain::folder& folder);
93 connections::domain::folder getFolder() const;
94 void setInitialParent(const std::optional<boost::uuids::uuid>& parentId);
95
96 // Environment operations (pure host+port)
97 void setEnvironment(const connections::domain::environment& env);
98 connections::domain::environment getEnvironment() const;
99
100 // Connection operations
101 void setConnection(const connections::domain::connection& conn);
102 connections::domain::connection getConnection() const;
103 void setInitialFolder(const std::optional<boost::uuids::uuid>& folderId);
104 std::optional<std::string> getPassword() const;
105
106 // Tags (environment and connection)
107 void setTags(const std::vector<connections::domain::tag>& tags);
108 std::vector<boost::uuids::uuid> getSelectedTagIds() const;
109
110 // Test callback (connection only)
111 void setTestCallback(TestConnectionCallback callback);
112
113 QString itemName() const;
114
115signals:
116 void statusMessage(const QString& message);
117 void errorMessage(const QString& message);
118 void folderSaved(const boost::uuids::uuid& id, const QString& name);
119 void environmentSaved(const boost::uuids::uuid& id, const QString& name);
120 void connectionSaved(const boost::uuids::uuid& id, const QString& name);
121
122private slots:
123 void onSaveClicked();
124 void onTestClicked();
125 void onTypeChanged(int index);
126 void onPasswordChanged();
127 void onEnvironmentComboChanged(int index);
128 void togglePasswordVisibility();
129 void updateSaveButtonState();
130
131private:
132 void setupUI();
133 void setupToolbar();
134 void populateFolderCombo();
135 void populateEnvironmentCombo();
136 void updateFieldVisibility();
137 bool validateInput();
138 void saveFolder();
139 void saveEnvironment();
140 void saveConnection();
141
143
144 // Toolbar
145 QToolBar* toolBar_;
146 QAction* saveAction_;
147 QAction* testAction_;
148
149 // Type selector
150 QComboBox* typeCombo_;
151
152 // Common fields
153 QLineEdit* nameEdit_;
154 QComboBox* folderCombo_;
155 QTextEdit* descriptionEdit_;
156
157 // Connection-only: environment link
158 QLabel* environmentLabel_;
159 QComboBox* environmentCombo_;
160
161 // Environment and Connection fields
162 QLabel* hostLabel_;
163 QLineEdit* hostEdit_;
164 QLabel* portLabel_;
165 QSpinBox* portSpinBox_;
166 QLabel* httpPortLabel_;
167 QSpinBox* httpPortSpinBox_;
168 QLabel* namespaceLabel_;
169 QLineEdit* namespaceEdit_;
170
171 // Connection-only fields
172 QLabel* usernameLabel_;
173 QLineEdit* usernameEdit_;
174 QLabel* passwordLabel_;
175 QLineEdit* passwordEdit_;
176 QCheckBox* showPasswordCheckbox_;
177 QWidget* passwordWidget_;
178
179 // Tags (environment and connection)
180 QLabel* tagLabel_;
181 TagSelectorWidget* tagSelector_;
182
183 // State
184 ItemType itemType_{ItemType::Connection};
185 bool isCreateMode_{true};
186 bool passwordChanged_{false};
187
188 // IDs for edit mode
189 boost::uuids::uuid folderId_;
190 boost::uuids::uuid pureEnvironmentId_;
191 boost::uuids::uuid connectionId_;
192
193 // Linked environment for connections (selected from combo)
194 std::optional<boost::uuids::uuid> linkedEnvironmentId_;
195
196 TestConnectionCallback testCallback_;
197};
198
199}
200
201#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
ItemType
Item type selector for the combined add dialog.
Definition AddItemDialog.hpp:54
std::function< QString(const QString &host, int port, const QString &username, const QString &password)> TestConnectionCallback
Callback type for testing connections.
Definition ConnectionTypes.hpp:36
Represents a saved connection with credentials.
Definition connection.hpp:40
Represents a pure server environment (host + port only, no credentials).
Definition environment.hpp:39
Represents a folder for organizing server connections hierarchically.
Definition folder.hpp:35
High-level service for managing server connections and environments.
Definition connection_manager.hpp:53
Utilities for reading environment variables.
Definition environment.hpp:31
Combined modeless dialog for creating and editing folders, environments, and connections.
Definition AddItemDialog.hpp:67
Widget for selecting and displaying tags as pill badges.
Definition TagSelectorWidget.hpp:43