aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b5ec81e..a66945c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,6 +9,8 @@
#include "../include/Settings.hpp"
#include "../include/ColorScheme.hpp"
#include "../include/GlobalContextMenu.hpp"
+#include "../include/StringUtils.hpp"
+#include "../include/ImagePreview.hpp"
#include <string>
#include <SFML/Graphics.hpp>
#include <cstring>
@@ -19,7 +21,6 @@
#include <odhtdb/hex2bin.hpp>
#include <ntp/NtpClient.hpp>
#include <sibs/SafeSerializer.hpp>
-#include <process.hpp>
#include <X11/Xlib.h>
using namespace std;
@@ -46,16 +47,6 @@ static void channelChangeUserNickname(Channel *channel, const StringView data, c
// We dont care if there is more data to read (malicious packet), we already got all the data we need
}
-static void stringReplaceChar(string &str, const string &from, const string &to)
-{
- size_t pos = 0;
- while((pos = str.find(from, pos)) != string::npos)
- {
- str.replace(pos, from.size(), to);
- pos += to.size();
- }
-}
-
static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, const odhtdb::Signature::PublicKey &creatorPublicKey, const StringView decryptedObject, u64 timestamp)
{
User *user = channel->getUserByPublicKey(creatorPublicKey);
@@ -78,12 +69,11 @@ static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &reques
if(!focused)
{
stringReplaceChar(msg, "'", "");
- stringReplaceChar(msg, "\"", "");
stringReplaceChar(msg, "\\", "");
string cmd = "notify-send dchat '";
cmd += msg;
cmd += "'";
- TinyProcessLib::Process notifySend(cmd, "");
+ system(cmd.c_str());
}
break;
}
@@ -681,28 +671,36 @@ int main(int argc, char **argv)
else if(event.type == sf::Event::Resized)
{
sf::FloatRect viewRect(0.0f, 0.0f, event.size.width, event.size.height);
+ /* // TODO: Use xlib to set window minimum size instead
const int minWidth = 800;
if(event.size.width < minWidth)
{
viewRect.width = minWidth;
window.setSize(sf::Vector2u(minWidth, event.size.height));
}
-
+ */
sf::View view(viewRect);
window.setView(view);
}
- else if(event.type == sf::Event::GainedFocus)
+ else if(event.type == sf::Event::MouseEntered)
window.setFramerateLimit(FRAMERATE_FOCUSED);
- //else if(event.type == sf::Event::LostFocus)
+ //else if(event.type == sf::Event::MouseLeft)
// window.setFramerateLimit(FRAMERATE_NOT_FOCUSED);
- if(event.type == sf::Event::GainedFocus)
+ if(event.type == sf::Event::MouseEntered)
focused = true;
- else if(event.type == sf::Event::LostFocus)
+ else if(event.type == sf::Event::MouseLeft)
focused = false;
- GlobalContextMenu::processEvent(event);
- currentChannel->processEvent(event);
+ if(focused)
+ {
+ ImagePreview::processEvent(event);
+ if(!ImagePreview::getPreviewContentPtr() && ImagePreview::getTimeSinceLastSeenMs() > 250)
+ {
+ GlobalContextMenu::processEvent(event);
+ currentChannel->processEvent(event, cache);
+ }
+ }
}
window.clear(ColorScheme::getBackgroundColor());
@@ -711,6 +709,7 @@ int main(int argc, char **argv)
UsersSidePanel::draw(window, cache);
ChannelTopPanel::draw(window);
GlobalContextMenu::draw(window);
+ ImagePreview::draw(window);
if(waitingToJoin)
{