Line data Source code
1 : #pragma once
2 :
3 : #include <QWidget>
4 :
5 : class QLineEdit;
6 : class QSpinBox;
7 : class QComboBox;
8 : class QLabel;
9 : class QPushButton;
10 : class QGroupBox;
11 : class QAction;
12 :
13 : class ImapService;
14 : struct AccountConfig;
15 :
16 : // Reusable account configuration form.
17 : // Used by both SettingsDialog and SetupWizard.
18 : // This widget only handles data entry – it does NOT save or cancel.
19 : // The parent dialog controls the save/cancel flow.
20 : class AccountFormWidget : public QWidget {
21 2069 : Q_OBJECT
22 :
23 : public:
24 : explicit AccountFormWidget(QWidget *parent = nullptr);
25 : ~AccountFormWidget() override;
26 :
27 : // Populate the form from an existing config
28 : void setConfig(const AccountConfig &config);
29 :
30 : // Read the current form values into an AccountConfig
31 : AccountConfig config() const;
32 :
33 : // Validate form fields, returns error messages (empty = valid)
34 : QStringList validate() const;
35 :
36 : // Check if any field has been modified since last setConfig()
37 : bool isModified() const;
38 :
39 : // Reset modified state (called after saving)
40 : void resetModified();
41 :
42 : // Clear all fields
43 : void clear();
44 :
45 : signals:
46 : // Emitted whenever any field changes
47 : void formChanged();
48 :
49 : public slots:
50 : // Start an async IMAP connection test with current form values
51 : void testConnection();
52 :
53 : protected:
54 : void changeEvent(QEvent *event) override;
55 :
56 : private:
57 : void setupUi();
58 : void setupTabOrder();
59 : void connectFieldSignals();
60 : void retranslateUi();
61 : void setTestResult(const QString &message, bool success);
62 :
63 : // Account basics
64 : QLineEdit *m_nameEdit = nullptr;
65 : QLineEdit *m_emailEdit = nullptr;
66 :
67 : // IMAP fields
68 : QGroupBox *m_imapGroup = nullptr;
69 : QLineEdit *m_imapHost = nullptr;
70 : QSpinBox *m_imapPort = nullptr;
71 : QComboBox *m_imapSecurity = nullptr;
72 : QLineEdit *m_imapUsername = nullptr;
73 : QLineEdit *m_imapPassword = nullptr;
74 :
75 : // SMTP fields
76 : QGroupBox *m_smtpGroup = nullptr;
77 : QLineEdit *m_smtpHost = nullptr;
78 : QSpinBox *m_smtpPort = nullptr;
79 : QComboBox *m_smtpSecurity = nullptr;
80 : QLineEdit *m_smtpUsername = nullptr;
81 : QLineEdit *m_smtpPassword = nullptr;
82 :
83 : // Connection test
84 : QPushButton *m_testButton = nullptr;
85 : QLabel *m_testResultLabel = nullptr;
86 : ImapService *m_testService = nullptr;
87 :
88 : // Form labels and password-toggle actions (held for retranslateUi)
89 : QLabel *m_nameLabel = nullptr;
90 : QLabel *m_emailLabel = nullptr;
91 : QLabel *m_imapHostLabel = nullptr;
92 : QLabel *m_imapPortLabel = nullptr;
93 : QLabel *m_imapSecurityLabel = nullptr;
94 : QLabel *m_imapUsernameLabel = nullptr;
95 : QLabel *m_imapPasswordLabel = nullptr;
96 : QLabel *m_smtpHostLabel = nullptr;
97 : QLabel *m_smtpPortLabel = nullptr;
98 : QLabel *m_smtpSecurityLabel = nullptr;
99 : QLabel *m_smtpUsernameLabel = nullptr;
100 : QLabel *m_smtpPasswordLabel = nullptr;
101 : QAction *m_imapToggleAction = nullptr;
102 : QAction *m_smtpToggleAction = nullptr;
103 :
104 : bool m_modified = false;
105 : };
|