-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.h
More file actions
304 lines (245 loc) · 9.8 KB
/
MainWindow.h
File metadata and controls
304 lines (245 loc) · 9.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Reikooters <https://github.com/Reikooters>
#ifndef KERYTHING_MAINWINDOW_H
#define KERYTHING_MAINWINDOW_H
#include <QMainWindow>
#include <QLineEdit>
#include <QTableView>
#include <QLabel>
#include <QString>
#include <QTimer>
#include <QComboBox>
#include <QRect>
#include <QVariantList>
#include <QtDBus/QDBusServiceWatcher>
#include <vector>
#include <string>
#include <memory>
#include "ScannerEngine.h"
#include "DbusIndexerClient.h"
class FileModel;
class RemoteFileModel;
/**
* @brief The main application window for searching and viewing files.
*/
class MainWindow : public QMainWindow {
Q_OBJECT
public:
/**
* @brief Constructs the MainWindow.
*/
explicit MainWindow(QWidget *parent = nullptr);
/**
* @brief Updates the current database and UI.
*/
void setDatabase(ScannerEngine::SearchDatabase&& database, QString mountPath, QString devicePath, const QString& fsType);
/**
* @brief Retrieves the index of the currently hovered row in the table view.
*
* This method returns the row index that is currently being hovered by the
* mouse pointer. If no row is hovered, it returns -1.
*
* @return The index of the hovered row, or -1 if no row is hovered.
*/
int hoveredRow() const { return m_hoveredRow; }
protected:
/**
* @brief Handles right-click events to show the file context menu.
*/
void contextMenuEvent(QContextMenuEvent *event) override;
/**
* @brief Filters events for specific objects in the application.
*
* This method intercepts and handles events for the given watched object
* and applies custom behavior. If the event is not explicitly handled,
* it delegates the processing to the base class implementation.
*
* @param watched The QObject that this method is filtering events for.
* @param event The QEvent being intercepted for this object.
* @return True if the event is handled and should not propagate further;
* otherwise returns false to pass the event to the base class or default handlers.
*/
bool eventFilter(QObject* watched, QEvent* event) override;
void closeEvent(QCloseEvent* event) override;
void changeEvent(QEvent* event) override;
void showEvent(QShowEvent* event) override;
private slots:
/**
* @brief Handles the event of a daemon service being registered.
*
* This method is triggered when a daemon service becomes available or restarts.
* It updates the daemon status and refreshes the current query page if necessary.
*
* @param serviceName The name of the registered daemon service.
*/
void onDaemonServiceRegistered(const QString& serviceName);
/**
* @brief Handles the event when a daemon service is unregistered.
*
* This method updates the UI and internal states to reflect the disconnection
* of the specified daemon service. It ensures users are informed about the
* unavailability of live updates and transitions the search model to an offline
* state if necessary.
*
* @param serviceName The name of the daemon service that was unregistered.
*/
void onDaemonServiceUnregistered(const QString& serviceName);
void onDaemonStateChanged(quint32 uid, const QString& state, const QVariantMap& props);
/**
* @brief Updates the device index and refreshes the search results in the UI.
*
* This slot is triggered when the device index is updated. It ensures that
* the search results are refreshed based on the new index data, particularly
* when using the daemon search functionality.
*
* @param deviceId The unique identifier of the device whose index was updated.
* @param generation The generation number of the updated index.
* @param entryCount The number of entries in the updated index.
*/
void onDeviceIndexUpdated(const QString& deviceId, quint64 generation, quint64 entryCount);
/**
* @brief Tracks which row is currently hovered so we can paint a full-row hover highlight.
*/
void onTableHovered(const QModelIndex& index);
/**
* @brief Tracks when the empty area of the table is hovered (below the last item in the list)
*/
void onTableViewportHovered();
/**
* @brief Triggered when the search text changes. Performs a trigram search and updates the view.
*/
void updateSearch(const QString &text);
/**
* @brief Opens the settings dialog for modifying application preferences.
*
* This method displays the settings dialog, allowing the user to configure
* application preferences. If no D-Bus client is available, a warning is
* displayed. After the settings are modified, the daemon status label is
* refreshed, and remote search results are invalidated if applicable.
*/
void openSettings();
/**
* @brief Shows a placeholder for the change partition logic.
*/
void changePartition();
/**
* @brief Shows a placeholder for the rescan partition logic.
*/
void rescanPartition();
/**
* @brief Shows the About dialog using KAboutData.
*/
void showAbout();
/**
* @brief Opens the selected file or folder using system defaults.
*/
void openFile(const QModelIndex &index);
/**
* @brief Opens all currently selected files in the table.
*/
void openSelectedFiles();
/**
* @brief Opens the folder containing the currently selected file.
*/
void openSelectedLocation();
/**
* @brief Copies the names of the selected items to the clipboard.
*/
void copyFileNames();
/**
* @brief Copies the full paths of selected items to the clipboard.
*/
void copyPaths();
/**
* @brief Copies the selected files themselves to the clipboard (for pasting in Dolphin).
*/
void copyFiles();
/**
* @brief Opens a terminal in the folder of the selected item.
*/
void openTerminal();
private:
/**
* @brief Performs the high-speed trigram-based keyword search.
*/
std::vector<uint32_t> performTrigramSearch(const std::string& query);
/**
* @brief Case-insensitive substring helper.
*/
static bool contains(std::string_view haystack, std::string_view needle);
// Async daemon startup so GUI doesn't block on snapshot loading
void beginAsyncDaemonInit();
void setDaemonReady(bool ready, const QString& reason = QString());
void requestDeviceListsAsync();
void refreshDaemonStatusLabelFromCachedLists();
void refreshDeviceScopeComboFromCachedLists();
/**
* @brief Updates the status label to reflect the current state of the daemon connection.
*
* This function checks the connection to the D-Bus and updates the status label accordingly.
* It handles the following scenarios:
* - If the D-Bus is not initialized, it indicates that the daemon is disconnected and live
* updates are paused.
* - If the daemon ping fails, the disconnection is reported along with the error message.
* - If fetching the list of indexed devices fails, the connection status is shown with an
* error message indicating the issue with retrieving indexes.
* - If connected and indexes are available, the label displays the number of indexed
* partitions and total objects indexed by the daemon.
*/
void refreshDaemonStatusLabel();
void refreshDeviceScopeCombo();
void loadUiSettings();
void saveUiSettings() const;
void applyPersistedSortToView();
void loadWindowPlacement();
void saveWindowPlacement() const;
// --- Table header (column width/state) persistence ---
void loadTableHeaderState();
void scheduleSaveTableHeaderState();
void saveTableHeaderState() const;
// --- end table header persistence ---
void updateLegacyPartitionActions();
void showBaselineStatus(const QString& msg);
void showTransientStatus(const QString& msg, int timeoutMs);
QAction* m_settingsAction = nullptr;
QAction* m_changePartitionAction = nullptr;
QAction* m_rescanPartitionAction = nullptr;
bool m_useDaemonSearch = false;
ScannerEngine::SearchDatabase db;
QString m_fsType;
QString m_mountPath;
QString m_devicePath;
QLineEdit *searchLine = nullptr;
QComboBox* m_deviceScopeCombo = nullptr;
QString m_selectedDeviceScopeId; // empty = all devices
QTableView *tableView = nullptr;
FileModel *model = nullptr; // local model
RemoteFileModel *remoteModel = nullptr; // daemon model
QLabel *daemonStatusLabel = nullptr;
std::unique_ptr<DbusIndexerClient> m_dbus;
QDBusServiceWatcher* m_daemonWatcher = nullptr;
QTimer* m_indexUpdateDebounceTimer = nullptr;
bool m_indexUpdatePending = false;
int m_hoveredRow = -1;
QString m_statusBaseline;
quint64 m_statusMessageToken = 0;
int m_sortColumn = 0;
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
// Used for *startup restore* only; the checkbox lives in SettingsDialog (QSettings).
bool m_persistLastQuery = false;
QString m_initialQueryText;
QRect m_lastNormalGeometry; // last geometry when NOT maximized/fullscreen
Qt::WindowStates m_lastWindowState = {}; // to detect transitions
bool m_initialPlacementApplied = false; // enforce geometry once after first show
// Header save debounce + guard to avoid saving during restore
QTimer* m_tableHeaderSaveDebounceTimer = nullptr;
bool m_restoringTableHeaderState = false;
// Async daemon init state
bool m_daemonReady = false;
bool m_daemonInitInFlight = false;
bool m_knownDevicesLoaded = false;
bool m_indexedDevicesLoaded = false;
QVariantList m_knownDevicesCached;
QVariantList m_indexedDevicesCached;
};
#endif //KERYTHING_MAINWINDOW_H