diff options
Diffstat (limited to 'trunk/src')
-rw-r--r-- | trunk/src/AbstractSecushareController.cpp | 242 | ||||
-rw-r--r-- | trunk/src/AbstractSecushareView.cpp | 13 | ||||
-rw-r--r-- | trunk/src/AbstractUserConfigModel.cpp | 8 | ||||
-rw-r--r-- | trunk/src/CMakeLists.txt | 61 | ||||
-rw-r--r-- | trunk/src/Identity.cpp | 27 | ||||
-rw-r--r-- | trunk/src/NotifyPipe.cpp | 36 | ||||
-rw-r--r-- | trunk/src/Place.cpp | 9 | ||||
-rw-r--r-- | trunk/src/QtUserConfigModel.cpp | 44 | ||||
-rw-r--r-- | trunk/src/RedThreadQt.cpp | 40 | ||||
-rw-r--r-- | trunk/src/SecushareQtController.cpp | 44 | ||||
-rw-r--r-- | trunk/src/SecushareQtView.cpp | 77 | ||||
-rw-r--r-- | trunk/src/main.cpp | 21 |
12 files changed, 622 insertions, 0 deletions
diff --git a/trunk/src/AbstractSecushareController.cpp b/trunk/src/AbstractSecushareController.cpp new file mode 100644 index 0000000..db720fb --- /dev/null +++ b/trunk/src/AbstractSecushareController.cpp | |||
@@ -0,0 +1,242 @@ | |||
1 | /** | ||
2 | * @file AbstractSecushareController.cpp | ||
3 | * @brief Abstract controller class | ||
4 | * | ||
5 | * @author lurchi | ||
6 | * @date 2016-02-05 | ||
7 | * | ||
8 | * @copyright | ||
9 | * This file is part of redthread which may be redistributed and/or modified | ||
10 | * under the terms of the GNU General Public License, either version 3 or any | ||
11 | * later version. See COPYING and <http://www.gnu.org/licenses/>. | ||
12 | */ | ||
13 | |||
14 | #include "AbstractSecushareController.hpp" | ||
15 | #include <iostream> | ||
16 | #include <vector> | ||
17 | |||
18 | using namespace redthread; | ||
19 | |||
20 | AbstractSecushareController::AbstractSecushareController( | ||
21 | std::shared_ptr<AbstractSecushareView> view, | ||
22 | const std::string& appName, | ||
23 | const std::string& appVersion, | ||
24 | const std::string& configPath | ||
25 | ) | ||
26 | : mView {view}, | ||
27 | mAppName {appName}, | ||
28 | mAppVersion {appVersion}, | ||
29 | mConfigFilePath {configPath}, | ||
30 | mRunning {false} | ||
31 | { | ||
32 | auto config = mView->getUserConfigModel(); | ||
33 | |||
34 | // TODO: read config from disk | ||
35 | config->setShowNewIdentityDialog(true); | ||
36 | } | ||
37 | |||
38 | int AbstractSecushareController::run() | ||
39 | { | ||
40 | const std::vector<struct GNUNET_GETOPT_CommandLineOption> options | ||
41 | { | ||
42 | GNUNET_GETOPT_OPTION_END | ||
43 | }; | ||
44 | |||
45 | std::string configFileOption {"-c"}; | ||
46 | |||
47 | const std::vector<char*> argv | ||
48 | { | ||
49 | &mAppName[0], | ||
50 | &configFileOption[0], | ||
51 | &mConfigFilePath[0] | ||
52 | }; | ||
53 | |||
54 | mRunning = true; | ||
55 | |||
56 | return | ||
57 | GNUNET_PROGRAM_run(argv.size(), | ||
58 | argv.data(), | ||
59 | mAppName.data(), | ||
60 | gettext_noop("binary description text"), | ||
61 | options.data(), | ||
62 | &AbstractSecushareController::runCb, | ||
63 | this); | ||
64 | } | ||
65 | |||
66 | void AbstractSecushareController::addExternalEventFD() | ||
67 | { | ||
68 | auto fileHandle = GNUNET_DISK_get_handle_from_int_fd(mGnunetTaskPipe.receiverFd()); | ||
69 | |||
70 | mExternalEventFdHandle = | ||
71 | GNUNET_SCHEDULER_add_read_file | ||
72 | ( | ||
73 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
74 | fileHandle, | ||
75 | &AbstractSecushareController::processGnunetTasksCb, | ||
76 | this | ||
77 | ); | ||
78 | |||
79 | } | ||
80 | |||
81 | void AbstractSecushareController::addToGnunetTaskQueue(std::function<void()> task) | ||
82 | { | ||
83 | { | ||
84 | std::lock_guard<std::mutex> lock {mGnunetTasksMutex}; | ||
85 | mGnunetTasks.push(task); | ||
86 | } | ||
87 | |||
88 | mGnunetTaskPipe.notify(); | ||
89 | } | ||
90 | |||
91 | void AbstractSecushareController::processGnunetTasksCb( | ||
92 | void* closure, | ||
93 | const struct GNUNET_SCHEDULER_TaskContext* context | ||
94 | ) | ||
95 | { | ||
96 | //DEBUG | ||
97 | std::cout << "AbstractSecushareController::processGnunetTasksCb" << std::endl; | ||
98 | |||
99 | AbstractSecushareController* controller {static_cast<AbstractSecushareController*>(closure)}; | ||
100 | auto& tasks = controller->mGnunetTasks; | ||
101 | |||
102 | { | ||
103 | std::lock_guard<std::mutex> lock {controller->mGnunetTasksMutex}; | ||
104 | |||
105 | while(not tasks.empty()) | ||
106 | { | ||
107 | tasks.front()(); | ||
108 | tasks.pop(); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | if(controller->mRunning) | ||
113 | { | ||
114 | controller->addExternalEventFD(); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | void AbstractSecushareController::runCb( | ||
119 | void* closure, | ||
120 | char* const* args, | ||
121 | const char* configFilePath, | ||
122 | const struct GNUNET_CONFIGURATION_Handle* configHandle | ||
123 | ) | ||
124 | { | ||
125 | AbstractSecushareController* controller {static_cast<AbstractSecushareController*>(closure)}; | ||
126 | |||
127 | controller->mConfigHandle = configHandle; | ||
128 | |||
129 | controller->mAppHandle = | ||
130 | GNUNET_SOCIAL_app_connect( | ||
131 | configHandle, | ||
132 | controller->mAppName.c_str(), | ||
133 | &AbstractSecushareController::egoAvailableCb, | ||
134 | &AbstractSecushareController::placeAvailableAsHostCb, | ||
135 | &AbstractSecushareController::placeAvailableAsGuestCb, | ||
136 | closure | ||
137 | ); | ||
138 | |||
139 | controller->mIdentityHandle = | ||
140 | GNUNET_IDENTITY_connect(controller->mConfigHandle, | ||
141 | &AbstractSecushareController::egoCreatedCb, | ||
142 | controller); | ||
143 | |||
144 | controller->addExternalEventFD(); | ||
145 | } | ||
146 | |||
147 | void AbstractSecushareController::shutdown() | ||
148 | { | ||
149 | addToGnunetTaskQueue( | ||
150 | [this]() | ||
151 | { | ||
152 | GNUNET_IDENTITY_disconnect(mIdentityHandle); | ||
153 | GNUNET_SOCIAL_app_disconnect(mAppHandle); | ||
154 | } | ||
155 | ); | ||
156 | |||
157 | mRunning = false; | ||
158 | } | ||
159 | |||
160 | void AbstractSecushareController::addEgo(const std::string& name) | ||
161 | { | ||
162 | addToGnunetTaskQueue( | ||
163 | [this, &name]() | ||
164 | { | ||
165 | GNUNET_IDENTITY_create( | ||
166 | mIdentityHandle, | ||
167 | name.data(), | ||
168 | &AbstractSecushareController::operationFinishedCb, | ||
169 | this | ||
170 | ); | ||
171 | } | ||
172 | ); | ||
173 | } | ||
174 | |||
175 | void AbstractSecushareController::addFriend(const std::string& nymPubKey, const std::string& name) | ||
176 | { | ||
177 | |||
178 | } | ||
179 | |||
180 | void AbstractSecushareController::sendMessage(const PlaceId& placeId, const std::string& message) | ||
181 | { | ||
182 | |||
183 | } | ||
184 | |||
185 | void AbstractSecushareController::egoAvailableCb( | ||
186 | void* closure, | ||
187 | struct GNUNET_SOCIAL_Ego* ego, | ||
188 | const struct GNUNET_CRYPTO_EcdsaPublicKey* egoPubKey, | ||
189 | const char* name | ||
190 | ) | ||
191 | { | ||
192 | std::cout << "ego available: " << GNUNET_CRYPTO_ecdsa_public_key_to_string (egoPubKey) << std::endl; | ||
193 | } | ||
194 | |||
195 | void AbstractSecushareController::placeAvailableAsHostCb( | ||
196 | void* closure, | ||
197 | struct GNUNET_SOCIAL_HostConnection* connection, | ||
198 | struct GNUNET_SOCIAL_Ego* ego, | ||
199 | const struct GNUNET_CRYPTO_EddsaPublicKey* hostPubKey, | ||
200 | enum GNUNET_SOCIAL_PlaceState placeState | ||
201 | ) | ||
202 | { | ||
203 | struct GNUNET_HashCode hostPubKeyHash; | ||
204 | GNUNET_CRYPTO_hash (hostPubKey, sizeof (*hostPubKey), &hostPubKeyHash); | ||
205 | std::cout << "place available as host: " << GNUNET_h2s(&hostPubKeyHash) << std::endl; | ||
206 | } | ||
207 | |||
208 | void AbstractSecushareController::placeAvailableAsGuestCb( | ||
209 | void* closure, | ||
210 | struct GNUNET_SOCIAL_GuestConnection* connection, | ||
211 | struct GNUNET_SOCIAL_Ego* ego, | ||
212 | const struct GNUNET_CRYPTO_EddsaPublicKey* guestPubKey, | ||
213 | enum GNUNET_SOCIAL_PlaceState placeState | ||
214 | ) | ||
215 | { | ||
216 | struct GNUNET_HashCode guestPubKeyHash; | ||
217 | GNUNET_CRYPTO_hash (guestPubKey, sizeof (*guestPubKey), &guestPubKeyHash); | ||
218 | std::cout << "place available as guest: " << GNUNET_h2s(&guestPubKeyHash) << std::endl; | ||
219 | } | ||
220 | |||
221 | void AbstractSecushareController::egoCreatedCb( | ||
222 | void *closure, | ||
223 | struct GNUNET_IDENTITY_Ego* ego, | ||
224 | void** ctx, | ||
225 | const char* name | ||
226 | ) | ||
227 | { | ||
228 | std::cout << "ego created" << name << std::endl; | ||
229 | } | ||
230 | |||
231 | void AbstractSecushareController::operationFinishedCb(void* closure, const char* errorMessage) | ||
232 | { | ||
233 | // DEBUG: | ||
234 | if(errorMessage) | ||
235 | { | ||
236 | std::cout << "ERROR: " << errorMessage << std::endl; | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | std::cout << "no error" << std::endl; | ||
241 | } | ||
242 | } | ||
diff --git a/trunk/src/AbstractSecushareView.cpp b/trunk/src/AbstractSecushareView.cpp new file mode 100644 index 0000000..2dfc460 --- /dev/null +++ b/trunk/src/AbstractSecushareView.cpp | |||
@@ -0,0 +1,13 @@ | |||
1 | // AbstractSecushareView.cpp | ||
2 | // | ||
3 | // author: lurchi | ||
4 | // date: 2016-02-01 | ||
5 | |||
6 | #include "AbstractSecushareView.hpp" | ||
7 | |||
8 | using namespace redthread; | ||
9 | |||
10 | AbstractSecushareView::AbstractSecushareView() | ||
11 | { | ||
12 | |||
13 | } | ||
diff --git a/trunk/src/AbstractUserConfigModel.cpp b/trunk/src/AbstractUserConfigModel.cpp new file mode 100644 index 0000000..bba79ed --- /dev/null +++ b/trunk/src/AbstractUserConfigModel.cpp | |||
@@ -0,0 +1,8 @@ | |||
1 | #include "AbstractUserConfigModel.hpp" | ||
2 | |||
3 | using namespace redthread; | ||
4 | |||
5 | AbstractUserConfigModel::AbstractUserConfigModel() | ||
6 | { | ||
7 | |||
8 | } | ||
diff --git a/trunk/src/CMakeLists.txt b/trunk/src/CMakeLists.txt new file mode 100644 index 0000000..cd186ca --- /dev/null +++ b/trunk/src/CMakeLists.txt | |||
@@ -0,0 +1,61 @@ | |||
1 | # src/CMakeLists.txt | ||
2 | |||
3 | include(CheckIncludeFileCXX) | ||
4 | |||
5 | set(THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party") | ||
6 | |||
7 | # gnunet | ||
8 | set(GNUNET_SOCIAL_NEEDED true) | ||
9 | find_package(Gnunet REQUIRED) | ||
10 | set(LIBS ${LIBS} ${GNUNET_LIBRARIES}) | ||
11 | set(REDTHREAD_INCLUDE_DIRS ${REDTHREAD_INCLUDE_DIRS} ${GNUNET_INCLUDE_DIRS}) | ||
12 | |||
13 | # ncurses | ||
14 | set(CURSES_NEED_NCURSES true) | ||
15 | find_package(Curses 6 REQUIRED) | ||
16 | set(LIBS ${LIBS} ${CURSES_LIBRARIES}) | ||
17 | set(REDTHREAD_INCLUDE_DIRS ${REDTHREAD_INCLUDE_DIRS} ${CURSES_INCLUDE_DIRS}) | ||
18 | |||
19 | # Qt | ||
20 | set(CMAKE_AUTOMOC ON) | ||
21 | find_package(Qt5Widgets REQUIRED) | ||
22 | find_package(Qt5Quick REQUIRED) | ||
23 | file(GLOB hpp_files "${PROJECT_SOURCE_DIR}/include/*.hpp") | ||
24 | qt_wrap_cpp(redthread qt_wrappers ${hpp_files}) | ||
25 | set(source_files ${source_files} ${qt_wrappers}) | ||
26 | set(LIBS ${LIBS} Qt5::Widgets Qt5::Quick) | ||
27 | |||
28 | # sigc++ | ||
29 | #find_package(SigC++ REQUIRED) | ||
30 | #set(LIBS ${LIBS} ${SIGC++_LIBRARIES}) | ||
31 | #set(REDTHREAD_INCLUDE_DIRS ${REDTHREAD_INCLUDE_DIRS} ${SIGC++_INCLUDE_DIRS}) | ||
32 | |||
33 | # boost::signals2 (header only) | ||
34 | #find_package(Boost REQUIRED) | ||
35 | #set(REDTHREAD_INCLUDE_DIRS ${REDTHREAD_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) | ||
36 | |||
37 | #set(CMAKE_CXX_FLAGS "-O2 -Os -std=c++11 -Wall -Wextra -pedantic -lstdc++" CACHE STRING "" FORCE) | ||
38 | set(CMAKE_CXX_FLAGS "-g -std=c++11 -Wall -Wextra") | ||
39 | set(CMAKE_EXE_LINKER_FLAGS "") | ||
40 | |||
41 | set(source_files ${source_files} | ||
42 | AbstractSecushareController.cpp | ||
43 | AbstractSecushareView.cpp | ||
44 | AbstractUserConfigModel.cpp | ||
45 | Identity.cpp | ||
46 | main.cpp | ||
47 | NotifyPipe.cpp | ||
48 | Place.cpp | ||
49 | QtUserConfigModel.cpp | ||
50 | RedThreadQt.cpp | ||
51 | SecushareQtController.cpp | ||
52 | SecushareQtView.cpp | ||
53 | ) | ||
54 | |||
55 | add_executable(redthread ${source_files}) | ||
56 | target_include_directories(redthread PUBLIC | ||
57 | ${REDTHREAD_INCLUDE_DIRS} | ||
58 | ${PROJECT_SOURCE_DIR} # for config.h | ||
59 | ${PROJECT_SOURCE_DIR}/include) | ||
60 | target_link_libraries(redthread ${LIBS}) | ||
61 | |||
diff --git a/trunk/src/Identity.cpp b/trunk/src/Identity.cpp new file mode 100644 index 0000000..61e5344 --- /dev/null +++ b/trunk/src/Identity.cpp | |||
@@ -0,0 +1,27 @@ | |||
1 | #include "Identity.hpp" | ||
2 | #include <algorithm> | ||
3 | |||
4 | using namespace redthread; | ||
5 | |||
6 | Identity::Identity(const std::string& masterPubKey, | ||
7 | const std::vector<std::string>& subordinatePubKeys) | ||
8 | : mMasterPubKey {masterPubKey}, mSubordinatePubKeys {subordinatePubKeys} | ||
9 | { | ||
10 | |||
11 | } | ||
12 | |||
13 | bool Identity::operator==(const Identity& other) const | ||
14 | { | ||
15 | return | ||
16 | (mMasterPubKey == other.mMasterPubKey) or | ||
17 | std::any_of( | ||
18 | other.mSubordinatePubKeys.cbegin(), | ||
19 | other.mSubordinatePubKeys.cend(), | ||
20 | [this](const std::string& k) | ||
21 | { | ||
22 | return | ||
23 | std::find(mSubordinatePubKeys.cbegin(), mSubordinatePubKeys.cend(), k) | ||
24 | != mSubordinatePubKeys.cend(); | ||
25 | } | ||
26 | ); | ||
27 | } | ||
diff --git a/trunk/src/NotifyPipe.cpp b/trunk/src/NotifyPipe.cpp new file mode 100644 index 0000000..3127cf4 --- /dev/null +++ b/trunk/src/NotifyPipe.cpp | |||
@@ -0,0 +1,36 @@ | |||
1 | #include "NotifyPipe.hpp" | ||
2 | |||
3 | #include <unistd.h> | ||
4 | #include <assert.h> | ||
5 | #include <fcntl.h> | ||
6 | |||
7 | using namespace Util; | ||
8 | |||
9 | NotifyPipe::NotifyPipe() | ||
10 | { | ||
11 | int pipefd[2]; | ||
12 | int ret = pipe(pipefd); | ||
13 | assert(ret == 0); // For real usage put proper check here | ||
14 | m_receiveFd = pipefd[0]; | ||
15 | m_sendFd = pipefd[1]; | ||
16 | fcntl(m_sendFd, F_SETFL, O_NONBLOCK); | ||
17 | } | ||
18 | |||
19 | |||
20 | NotifyPipe::~NotifyPipe() | ||
21 | { | ||
22 | close(m_sendFd); | ||
23 | close(m_receiveFd); | ||
24 | } | ||
25 | |||
26 | |||
27 | int NotifyPipe::receiverFd() | ||
28 | { | ||
29 | return m_receiveFd; | ||
30 | } | ||
31 | |||
32 | |||
33 | void NotifyPipe::notify() | ||
34 | { | ||
35 | write(m_sendFd, "1", 1); | ||
36 | } | ||
diff --git a/trunk/src/Place.cpp b/trunk/src/Place.cpp new file mode 100644 index 0000000..a2a36b0 --- /dev/null +++ b/trunk/src/Place.cpp | |||
@@ -0,0 +1,9 @@ | |||
1 | #include "Place.hpp" | ||
2 | |||
3 | using namespace redthread; | ||
4 | |||
5 | Place::Place(const std::string& pubKey, const IdentityId& owner) | ||
6 | : mPubKey {pubKey}, mOwner {owner} | ||
7 | { | ||
8 | |||
9 | } | ||
diff --git a/trunk/src/QtUserConfigModel.cpp b/trunk/src/QtUserConfigModel.cpp new file mode 100644 index 0000000..fb6b96c --- /dev/null +++ b/trunk/src/QtUserConfigModel.cpp | |||
@@ -0,0 +1,44 @@ | |||
1 | #include "QtUserConfigModel.hpp" | ||
2 | |||
3 | using namespace redthread; | ||
4 | |||
5 | QtUserConfigModel::QtUserConfigModel(QObject* parent) | ||
6 | : QAbstractItemModel(parent), AbstractUserConfigModel() | ||
7 | { | ||
8 | |||
9 | } | ||
10 | |||
11 | QtUserConfigModel::~QtUserConfigModel() | ||
12 | { | ||
13 | |||
14 | } | ||
15 | |||
16 | int QtUserConfigModel::columnCount(const QModelIndex & parent) const | ||
17 | { | ||
18 | // FIXME | ||
19 | return 0; | ||
20 | } | ||
21 | |||
22 | QVariant QtUserConfigModel::data(const QModelIndex & index, int role) const | ||
23 | { | ||
24 | // FIXME | ||
25 | return {}; | ||
26 | } | ||
27 | |||
28 | QModelIndex QtUserConfigModel::index(int row, int column, const QModelIndex & parent) const | ||
29 | { | ||
30 | // FIXME | ||
31 | return {}; | ||
32 | } | ||
33 | |||
34 | QModelIndex QtUserConfigModel::parent(const QModelIndex & index) const | ||
35 | { | ||
36 | // FIXME | ||
37 | return {}; | ||
38 | } | ||
39 | |||
40 | int QtUserConfigModel::rowCount(const QModelIndex & parent) const | ||
41 | { | ||
42 | // FIXME | ||
43 | return 0; | ||
44 | } | ||
diff --git a/trunk/src/RedThreadQt.cpp b/trunk/src/RedThreadQt.cpp new file mode 100644 index 0000000..63e0ca8 --- /dev/null +++ b/trunk/src/RedThreadQt.cpp | |||
@@ -0,0 +1,40 @@ | |||
1 | // RedThread.cpp | ||
2 | // | ||
3 | // author: lurchi | ||
4 | // date: 2016-02-01 | ||
5 | |||
6 | #include "RedThreadQt.hpp" | ||
7 | #include <QApplication> | ||
8 | |||
9 | using namespace redthread; | ||
10 | |||
11 | RedThreadQt::RedThreadQt(int argc, char** argv) | ||
12 | : mView {new SecushareQtView(argc, argv)}, | ||
13 | mController {mView, "redthread", "0.1", "/home/christian/.config/gnunet.conf"} | ||
14 | { | ||
15 | auto view = mView.get(); | ||
16 | auto controller = &mController; | ||
17 | |||
18 | QApplication::connect(view, &SecushareQtView::shutdownRequest, controller, &SecushareQtController::shutdown); | ||
19 | } | ||
20 | |||
21 | RedThreadQt::~RedThreadQt() | ||
22 | { | ||
23 | if(mControlThread.get_id() != std::thread::id {}) | ||
24 | { | ||
25 | mControlThread.join(); | ||
26 | } | ||
27 | } | ||
28 | |||
29 | int RedThreadQt::run() | ||
30 | { | ||
31 | mControlThread = std::thread {&SecushareQtController::run, &mController}; | ||
32 | |||
33 | /** | ||
34 | * FIXME: | ||
35 | * is there a race condition with GNUNET_SCHEDULER_run setting signal handlers? | ||
36 | */ | ||
37 | int exitCode {mView->run()}; | ||
38 | |||
39 | return exitCode; | ||
40 | } | ||
diff --git a/trunk/src/SecushareQtController.cpp b/trunk/src/SecushareQtController.cpp new file mode 100644 index 0000000..512cc67 --- /dev/null +++ b/trunk/src/SecushareQtController.cpp | |||
@@ -0,0 +1,44 @@ | |||
1 | // SecushareQtController.cpp | ||
2 | // | ||
3 | // author: lurchi | ||
4 | // date: 2016-02-01 | ||
5 | |||
6 | #include "SecushareQtController.hpp" | ||
7 | |||
8 | using namespace redthread; | ||
9 | |||
10 | SecushareQtController::SecushareQtController(std::shared_ptr<SecushareQtView> view, | ||
11 | const std::string& appName, | ||
12 | const std::string& appVersion, | ||
13 | const std::string& configPath, | ||
14 | QObject* parent) | ||
15 | : QObject(parent), | ||
16 | AbstractSecushareController(view, appName, appVersion, configPath) | ||
17 | { | ||
18 | |||
19 | } | ||
20 | |||
21 | SecushareQtController::~SecushareQtController() | ||
22 | { | ||
23 | |||
24 | } | ||
25 | |||
26 | void SecushareQtController::shutdown() | ||
27 | { | ||
28 | AbstractSecushareController::shutdown(); | ||
29 | } | ||
30 | |||
31 | void SecushareQtController::addEgo(const std::string& name) | ||
32 | { | ||
33 | AbstractSecushareController::addEgo(name); | ||
34 | } | ||
35 | |||
36 | void SecushareQtController::addFriend(const std::string& nymPubKey, const std::string& name) | ||
37 | { | ||
38 | AbstractSecushareController::addFriend(nymPubKey, name); | ||
39 | } | ||
40 | |||
41 | void SecushareQtController::sendMessage(const PlaceId& placeId, const std::string& message) | ||
42 | { | ||
43 | AbstractSecushareController::sendMessage(placeId, message); | ||
44 | } | ||
diff --git a/trunk/src/SecushareQtView.cpp b/trunk/src/SecushareQtView.cpp new file mode 100644 index 0000000..2253d58 --- /dev/null +++ b/trunk/src/SecushareQtView.cpp | |||
@@ -0,0 +1,77 @@ | |||
1 | // SecushareQtView.cpp | ||
2 | // | ||
3 | // author: lurchi | ||
4 | // date: 2016-02-01 | ||
5 | |||
6 | #include "SecushareQtView.hpp" | ||
7 | #include "config.h" | ||
8 | #include <signal.h> | ||
9 | #include <QQuickView> | ||
10 | #include <QQuickItem> | ||
11 | #include <QQmlEngine> | ||
12 | |||
13 | using namespace redthread; | ||
14 | |||
15 | Util::NotifyPipe SecushareQtView::shutdownPipe {}; | ||
16 | |||
17 | SecushareQtView::SecushareQtView(int argc, char** argv) | ||
18 | : QObject(), | ||
19 | AbstractSecushareView(), | ||
20 | mArgc {argc}, | ||
21 | mArgv {argv}, | ||
22 | mUserConfigModel {new QtUserConfigModel()} | ||
23 | { | ||
24 | std::cout << "SecushareQtView ctor" << std::endl; | ||
25 | } | ||
26 | |||
27 | SecushareQtView::~SecushareQtView() | ||
28 | { | ||
29 | |||
30 | } | ||
31 | |||
32 | void SecushareQtView::catchUnixSignals( | ||
33 | const std::vector<int>& quitSignals, | ||
34 | const std::vector<int>& ignoreSignals | ||
35 | ) | ||
36 | { | ||
37 | sigNotifier = new QSocketNotifier(shutdownPipe.receiverFd(), QSocketNotifier::Read, nullptr); | ||
38 | QApplication::connect(sigNotifier, &QSocketNotifier::activated, &QApplication::quit); | ||
39 | |||
40 | auto handler = [](int sig) -> void | ||
41 | { | ||
42 | shutdownPipe.notify(); | ||
43 | }; | ||
44 | |||
45 | // all these signals will be ignored. | ||
46 | for(int sig : ignoreSignals) | ||
47 | { | ||
48 | signal(sig, SIG_IGN); | ||
49 | } | ||
50 | |||
51 | // each of these signals calls the handler (quits the QCoreApplication). | ||
52 | for(int sig : quitSignals) | ||
53 | { | ||
54 | signal(sig, handler); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | int SecushareQtView::run() | ||
59 | { | ||
60 | QApplication app(mArgc, mArgv); | ||
61 | |||
62 | QObject::connect(&app, &QApplication::aboutToQuit, this, &SecushareQtView::shutdownRequest); | ||
63 | |||
64 | catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP}); | ||
65 | |||
66 | QQuickView view (QUrl::fromLocalFile(QML_DIR "/application.qml")); | ||
67 | QObject* root = view.rootObject(); | ||
68 | QQmlEngine *engine = QtQml::qmlEngine(root); | ||
69 | //QObject::connect(root, SIGNAL(shutdownButtonClicked()), this, SIGNAL(shutdownRequest())); | ||
70 | QObject::connect(engine, SIGNAL(quit()), this, SIGNAL(shutdownRequest())); | ||
71 | QObject::connect(engine, SIGNAL(quit()), &app, SLOT(quit())); | ||
72 | |||
73 | //view.setSource(QUrl::fromLocalFile(QML_DIR "/application.qml")); | ||
74 | view.show(); | ||
75 | |||
76 | return app.exec(); | ||
77 | } | ||
diff --git a/trunk/src/main.cpp b/trunk/src/main.cpp new file mode 100644 index 0000000..d505293 --- /dev/null +++ b/trunk/src/main.cpp | |||
@@ -0,0 +1,21 @@ | |||
1 | // main.cpp | ||
2 | // | ||
3 | // author: lurchi | ||
4 | // date: 2016-02-01 | ||
5 | |||
6 | #include "RedThreadQt.hpp" | ||
7 | #include <iostream> | ||
8 | |||
9 | int main(int argc, char** argv) | ||
10 | { | ||
11 | using namespace redthread; | ||
12 | |||
13 | std::cout << "red thread" << std::endl; | ||
14 | |||
15 | RedThreadQt app {argc, argv}; | ||
16 | int exitCode {app.run()}; | ||
17 | |||
18 | std::cout << "exiting with code " << exitCode << std::endl; | ||
19 | |||
20 | return exitCode; | ||
21 | } | ||