1
0
forked from blue/squawk
This commit is contained in:
Blue 2019-03-29 17:54:34 +03:00
commit de36fe2a4e
15 changed files with 421 additions and 0 deletions

27
CMakeLists.txt Normal file
View File

@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.0)
project(squawk)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Instruct CMake to create code from Qt designer ui files
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets CONFIG REQUIRED)
set(squawk_SRC
main.cpp
)
# Tell CMake to create the helloworld executable
add_executable(squawk ${squawk_SRC})
target_link_libraries(squawk Qt5::Widgets)
add_subdirectory(ui)
add_subdirectory(core)
target_link_libraries(squawk squawkUI)
target_link_libraries(squawk squawkCORE)
# Install the executable
install(TARGETS squawk DESTINATION bin)

0
README.md Normal file
View File

24
core/CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.0)
project(squawkCORE)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Network CONFIG REQUIRED)
set(squawkCORE_SRC
squawk.cpp
account.cpp
)
# Tell CMake to create the helloworld executable
add_library(squawkCORE ${squawkCORE_SRC})
# Use the Widgets module from Qt 5.
target_link_libraries(squawkCORE Qt5::Core)
target_link_libraries(squawkCORE Qt5::Network)
target_link_libraries(squawkCORE qxmpp)
# Install the executable
install(TARGETS squawkCORE DESTINATION lib)

17
core/account.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "account.h"
using namespace Core;
Account::Account(const QString& p_jid, const QString& p_password, QObject* parent):
QObject(parent),
jid(p_jid),
password(p_password),
client()
{
}
Account::~Account()
{
}

25
core/account.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef CORE_ACCOUNT_H
#define CORE_ACCOUNT_H
#include <QtCore/QObject>
#include <qxmpp/QXmppClient.h>
namespace Core
{
class Account : public QObject
{
public:
Account(const QString& p_jid, const QString& p_password, QObject* parent = 0);
~Account();
private:
QString jid;
QString password;
QXmppClient client;
};
}
#endif // CORE_ACCOUNT_H

15
core/squawk.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "squawk.h"
using namespace Core;
Squawk::Squawk(QObject* parent):
QObject(parent),
accounts()
{
}
Squawk::~Squawk()
{
}

27
core/squawk.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef CORE_SQUAWK_H
#define CORE_SQUAWK_H
#include <QtCore/QObject>
#include <deque>
#include "account.h"
namespace Core
{
class Squawk : public QObject
{
Q_OBJECT
public:
Squawk(QObject* parent = 0);
~Squawk();
private:
typedef std::deque<Account> Accounts;
Accounts accounts;
};
}
#endif // CORE_SQUAWK_H

24
main.cpp Normal file
View File

@ -0,0 +1,24 @@
#include "ui/squawk.h"
#include "core/squawk.h"
#include <QtWidgets/QApplication>
#include <QtCore/QThread>
#include <QtCore/QObject>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Squawk w;
w.show();
Core::Squawk* squawk = new Core::Squawk();
QThread* coreThread = new QThread();
squawk->moveToThread(coreThread);
QObject::connect(coreThread, SIGNAL(finished()), squawk, SLOT(deleteLater()));
//QObject::connect(this, &Controller::operate, worker, &Worker::doWork);
//QObject::connect(worker, &Worker::resultReady, this, &Controller::handleResults);
coreThread->start();
return app.exec();
}

24
ui/CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.0)
project(squawkUI)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Instruct CMake to create code from Qt designer ui files
set(CMAKE_AUTOUIC ON)
# Find the QtWidgets library
find_package(Qt5Widgets CONFIG REQUIRED)
set(squawkUI_SRC
squawk.cpp
accounts.cpp
)
# Tell CMake to create the helloworld executable
add_library(squawkUI ${squawkUI_SRC})
# Use the Widgets module from Qt 5.
target_link_libraries(squawkUI Qt5::Widgets)
# Install the executable
install(TARGETS squawkUI DESTINATION lib)

10
ui/accounts.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "accounts.h"
#include "ui_accounts.h"
Accounts::Accounts(QWidget *parent) :
m_ui(new Ui::Accounts)
{
m_ui->setupUi(this);
}
Accounts::~Accounts() = default;

26
ui/accounts.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef ACCOUNTS_H
#define ACCOUNTS_H
#include <QWidget>
#include <QScopedPointer>
namespace Ui
{
class Accounts;
}
/**
* @todo write docs
*/
class Accounts : public QWidget
{
Q_OBJECT
public:
explicit Accounts(QWidget *parent = nullptr);
~Accounts() override;
private:
QScopedPointer<Ui::Accounts> m_ui;
};
#endif // ACCOUNTS_H

73
ui/accounts.ui Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Accounts</class>
<widget class="QWidget" name="Accounts">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>768</width>
<height>235</height>
</rect>
</property>
<property name="windowTitle">
<string>Accounts</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="4">
<widget class="QTableView" name="tableView"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

43
ui/squawk.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "squawk.h"
#include "ui_squawk.h"
Squawk::Squawk(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::Squawk),
accounts(0)
{
m_ui->setupUi(this);
connect(m_ui->actionAccounts, SIGNAL(triggered()), this, SLOT(onAccounts()));
}
Squawk::~Squawk() {
}
void Squawk::onAccounts()
{
if (accounts == 0) {
accounts = new Accounts(this);
accounts->setAttribute(Qt::WA_DeleteOnClose);
connect(accounts, SIGNAL(destroyed(QObject*)), this, SLOT(onAccountsClosed(QObject*)));
accounts->show();
} else {
accounts->focusWidget();
}
}
void Squawk::closeEvent(QCloseEvent* event)
{
if (accounts != 0) {
accounts->close();
}
QMainWindow::closeEvent(event);
}
void Squawk::onAccountsClosed(QObject* parent)
{
accounts = 0;
}

35
ui/squawk.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef SQUAWK_H
#define SQUAWK_H
#include <QMainWindow>
#include <QScopedPointer>
#include <QCloseEvent>
#include "accounts.h"
namespace Ui {
class Squawk;
}
class Squawk : public QMainWindow
{
Q_OBJECT
public:
explicit Squawk(QWidget *parent = nullptr);
~Squawk() override;
private:
QScopedPointer<Ui::Squawk> m_ui;
Accounts* accounts;
protected:
void closeEvent(QCloseEvent * event) override;
private slots:
void onAccounts();
void onAccountsClosed(QObject* parent = 0);
};
#endif // SQUAWK_H

51
ui/squawk.ui Normal file
View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Squawk</class>
<widget class="QMainWindow" name="Squawk">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>squawk</string>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>27</height>
</rect>
</property>
<widget class="QMenu" name="menu">
<property name="title">
<string>Settings</string>
</property>
<addaction name="actionAccounts"/>
</widget>
<addaction name="menu"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionAccounts">
<property name="text">
<string>Accounts</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>