aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-29 08:17:30 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-29 08:17:36 +0200
commitf90a5705bd65a4ebb5edc9df003a383039fec555 (patch)
treef0180d946bddc15a0a13d9148562418cb3a4108e /src/main.cpp
parent68dcd3c4e17355e1c2b640fe1382743d7cb61ea2 (diff)
Change design, fix crash when closing application
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp60
1 files changed, 52 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 61319fa..580b362 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,10 +1,12 @@
#include "../include/Channel.hpp"
#include "../include/ChannelSidePanel.hpp"
#include "../include/UsersSidePanel.hpp"
+#include "../include/ChannelTopPanel.hpp"
#include "../include/Cache.hpp"
#include "../include/ResourceCache.hpp"
#include "../include/Video.hpp"
#include "../include/Command.hpp"
+#include "../include/Settings.hpp"
#include <string>
#include <SFML/Graphics.hpp>
#include <cstring>
@@ -97,7 +99,7 @@ int main(int argc, char **argv)
Channel offlineChannel("Offline");
ChannelSidePanel::addChannel(&offlineChannel);
- UsersSidePanel::setCurrentChannel(&offlineChannel);
+ Channel::setCurrent(&offlineChannel);
vector<Channel*> channels;
@@ -150,7 +152,7 @@ int main(int argc, char **argv)
ChannelSidePanel::addChannel(channel);
channels.push_back(channel);
- UsersSidePanel::setCurrentChannel(channel);
+ Channel::setCurrent(channel);
channelAddStoredMessages(channel, nodeStorage);
}
@@ -224,10 +226,10 @@ int main(int argc, char **argv)
Channel *channel = new Channel(args[0], databaseNode, newLocalUser, &database);
ChannelSidePanel::addChannel(channel);
channels.push_back(channel);
- UsersSidePanel::setCurrentChannel(channel);
+ Channel::setCurrent(channel);
});
- Command::add("jc", [&currentUserKeyPair, &database](const vector<string> &args)
+ Command::add("jc", [&currentUserKeyPair, &database, &localNodeUsers](const vector<string> &args)
{
if(args.size() != 1)
{
@@ -248,8 +250,47 @@ int main(int argc, char **argv)
}
odhtdb::DatabaseNode databaseNode = createDatabaseNodeFromJoinKey(args[0]);
- database.seed(databaseNode);
- // TODO: Continue this...
+ for(auto localNodeUser : localNodeUsers)
+ {
+ if(*databaseNode.getRequestHash() == localNodeUser.nodeHash)
+ {
+ fprintf(stderr, "You have already joined the channel %s\n", databaseNode.getRequestHash()->toString().c_str());
+ return;
+ }
+ }
+#if 0
+ User *newLocalUser = new OnlineUser(localNodeUser.localUser);
+ odhtdb::DatabaseNode databaseNode(nodeDecryptionKeyResult.second, make_shared<odhtdb::Hash>(localNodeUser.nodeHash));
+ Channel *channel = new Channel(nodeStorage->nodeName, databaseNode, newLocalUser, &database);
+
+ auto nodeUserMapByPublicKey = database.getStorage().getNodeUsers(localNodeUser.nodeHash);
+ for(auto nodeUserIt : *nodeUserMapByPublicKey)
+ {
+ if(nodeUserIt.second != localNodeUser.localUser)
+ {
+ User *newRemoteUser = new OnlineUser(nodeUserIt.second);
+ channel->addUser(newRemoteUser);
+ }
+ }
+
+ ChannelSidePanel::addChannel(channel);
+ channels.push_back(channel);
+ Channel::setCurrent(channel);
+ channelAddStoredMessages(channel, nodeStorage);
+#endif
+ });
+
+ Command::add("scaling", [](const vector<string> &args)
+ {
+ if(args.size() != 1)
+ {
+ fprintf(stderr, "Expected 1 argument for command scaling, got %u argument(s)\n", args.size());
+ return;
+ }
+
+ float scaling = stof(args[0]);
+ Settings::setScaling(scaling);
+ printf("UI scaling set to %f\n", scaling);
});
sf::Event event;
@@ -272,11 +313,14 @@ int main(int argc, char **argv)
sf::View view(viewRect);
window.setView(view);
}
- UsersSidePanel::getCurrentChannel()->processEvent(event);
+ Channel::getCurrent()->processEvent(event);
}
window.clear(sf::Color(40, 40, 40));
- UsersSidePanel::getCurrentChannel()->draw(window, cache);
+ ChannelSidePanel::draw(window);
+ Channel::getCurrent()->draw(window, cache);
+ UsersSidePanel::draw(window);
+ ChannelTopPanel::draw(window);
//video.draw(window);
window.display();
}