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/server_environment.hpp"
36#include "ores.connections/domain/tag.hpp"
37#include "ores.logging/make_logger.hpp"
38#include "ores.qt/ConnectionTypes.hpp"
39
40namespace ores::qt {
41class TagSelectorWidget;
42}
43
44namespace ores::connections::service {
45class connection_manager;
46}
47
48namespace ores::qt {
49
53enum class ItemType {
54 Folder,
55 Connection
56};
57
64class AddItemDialog : public QWidget {
65 Q_OBJECT
66
67private:
68 inline static std::string_view logger_name = "ores.qt.add_item_dialog";
69
70 [[nodiscard]] static auto& lg() {
71 using namespace ores::logging;
72 static auto instance = make_logger(logger_name);
73 return instance;
74 }
75
76public:
77 explicit AddItemDialog(
79 QWidget* parent = nullptr);
80 ~AddItemDialog() override;
81
82 void setItemType(ItemType type);
83 ItemType itemType() const { return itemType_; }
84
85 void setCreateMode(bool createMode);
86 bool isCreateMode() const { return isCreateMode_; }
87
88 // Folder operations
89 void setFolder(const connections::domain::folder& folder);
90 connections::domain::folder getFolder() const;
91 void setInitialParent(const std::optional<boost::uuids::uuid>& parentId);
92
93 // Connection operations
94 void setEnvironment(const connections::domain::server_environment& env);
95 connections::domain::server_environment getEnvironment() const;
96 void setInitialFolder(const std::optional<boost::uuids::uuid>& folderId);
97 std::optional<std::string> getPassword() const;
98
99 // Tags (connection only)
100 void setTags(const std::vector<connections::domain::tag>& tags);
101 std::vector<boost::uuids::uuid> getSelectedTagIds() const;
102
103 // Test callback (connection only)
104 void setTestCallback(TestConnectionCallback callback);
105
106 QString itemName() const;
107
108signals:
109 void statusMessage(const QString& message);
110 void errorMessage(const QString& message);
111 void folderSaved(const boost::uuids::uuid& id, const QString& name);
112 void connectionSaved(const boost::uuids::uuid& id, const QString& name);
113
114private slots:
115 void onSaveClicked();
116 void onTestClicked();
117 void onTypeChanged(int index);
118 void onPasswordChanged();
119 void togglePasswordVisibility();
120 void updateSaveButtonState();
121
122private:
123 void setupUI();
124 void setupToolbar();
125 void populateFolderCombo();
126 void updateFieldVisibility();
127 bool validateInput();
128 void saveFolder();
129 void saveConnection();
130
132
133 // Toolbar
134 QToolBar* toolBar_;
135 QAction* saveAction_;
136 QAction* testAction_;
137
138 // Type selector
139 QComboBox* typeCombo_;
140
141 // Common fields
142 QLineEdit* nameEdit_;
143 QComboBox* folderCombo_;
144 QTextEdit* descriptionEdit_;
145
146 // Connection-only fields
147 QLineEdit* hostEdit_;
148 QSpinBox* portSpinBox_;
149 QLineEdit* usernameEdit_;
150 QLineEdit* passwordEdit_;
151 QCheckBox* showPasswordCheckbox_;
152 TagSelectorWidget* tagSelector_;
153
154 // Labels for showing/hiding
155 QLabel* hostLabel_;
156 QLabel* portLabel_;
157 QLabel* usernameLabel_;
158 QLabel* passwordLabel_;
159 QLabel* tagLabel_;
160 QWidget* passwordWidget_;
161
162 // State
163 ItemType itemType_{ItemType::Connection};
164 bool isCreateMode_{true};
165 bool passwordChanged_{false};
166
167 // IDs for edit mode
168 boost::uuids::uuid folderId_;
169 boost::uuids::uuid environmentId_;
170
171 TestConnectionCallback testCallback_;
172};
173
174}
175
176#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
ItemType
Item type selector for the combined add dialog.
Definition AddItemDialog.hpp:53
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 folder for organizing server connections hierarchically.
Definition folder.hpp:35
Represents a server connection/environment configuration.
Definition server_environment.hpp:39
High-level service for managing server connections.
Definition connection_manager.hpp:48
Utilities for reading environment variables.
Definition environment.hpp:31
Combined modeless dialog for creating and editing folders and connections.
Definition AddItemDialog.hpp:64
Widget for selecting and displaying tags as pill badges.
Definition TagSelectorWidget.hpp:43