Files
yourls-ui/mainwindow.h

154 lines
3.2 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QUrl>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
class QAction;
class QCloseEvent;
class QMenu;
class YourlsClient;
/**
* @brief Main application window used as the settings page.
*
* When valid settings exist the application starts in the tray.
* The tray menu contains the main workflow action, "Cut URL",
* plus Help, About, Settings and Exit.
*/
class MainWindow : public QMainWindow {
Q_OBJECT
public:
/**
* @brief Constructs the main window.
* @param parent Parent widget.
*/
explicit MainWindow (QWidget *parent = nullptr);
/**
* @brief Destroys the main window.
*/
~MainWindow() override;
protected:
/**
* @brief Handles close requests.
* @param event Close event.
*/
void closeEvent (QCloseEvent *event) override;
private slots:
/**
* @brief Saves settings from the UI.
*/
void saveSettings();
/**
* @brief Shows About text.
*/
void showAbout();
/**
* @brief Shows Help text.
*/
void showHelp();
/**
* @brief Shows the settings window.
*/
void showSettingsWindow();
/**
* @brief Hides the settings window to tray when possible.
*/
void hideToTray();
/**
* @brief Exits the application.
*/
void exitApplication();
/**
* @brief Handles tray icon activation.
* @param reason Activation reason.
*/
void onTrayIconActivated (QSystemTrayIcon::ActivationReason reason);
/**
* @brief Reads a URL from the clipboard and shortens it.
*/
void cutUrlFromClipboard();
/**
* @brief Handles successful shortening.
* @param shortUrl Generated short URL.
*/
void onShortenSucceeded (const QUrl &shortUrl);
/**
* @brief Handles shortening failure.
* @param details Detailed error text.
*/
void onShortenFailed (const QString &details);
private:
/**
* @brief Creates tray icon and tray menu.
*/
void setupTray();
/**
* @brief Connects UI signals to slots.
*/
void setupConnections();
/**
* @brief Loads persisted settings into the UI.
*/
void loadSettings();
/**
* @brief Returns true when all required settings are present.
* @return True when the application can work from the tray.
*/
bool hasValidSettings() const;
/**
* @brief Validates and normalizes URL text.
* @param text Input text.
* @return Parsed URL.
*/
QUrl parseClipboardUrl (const QString &text) const;
/**
* @brief Shows a popup with the generated short URL.
* @param shortUrl Generated short URL.
*/
void showShortUrlPopup (const QUrl &shortUrl);
/**
* @brief Creates tray/menu actions.
*/
void setupMenuActions();
Ui::MainWindow *ui;
QSystemTrayIcon *m_trayIcon;
QMenu *m_trayMenu;
QAction *m_cutUrlAction;
QAction *m_settingsAction;
QAction *m_helpAction;
QAction *m_aboutAction;
QAction *m_exitAction;
YourlsClient *m_yourlsClient;
};
#endif // MAINWINDOW_H