Skip to content

Instantly share code, notes, and snippets.

@Vogtinator
Created January 18, 2018 21:54
Show Gist options
  • Save Vogtinator/ecc83fbfe5acdf3a411090b63760bdfc to your computer and use it in GitHub Desktop.
Save Vogtinator/ecc83fbfe5acdf3a411090b63760bdfc to your computer and use it in GitHub Desktop.
kmozillahelper patch
diff --git a/main.cpp b/main.cpp
index 6256b51..e5f23e9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -50,7 +50,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <KService/KMimeTypeTrader>
#include <KWindowSystem/KWindowSystem>
-//#define DEBUG_KDE
+#define DEBUG_KDE
#define HELPER_VERSION 6
#define APP_HELPER_VERSION "5.0.0"
@@ -81,13 +81,15 @@ Helper::Helper()
: notifier(STDIN_FILENO, QSocketNotifier::Read)
, arguments_read(false)
{
+ input.open(stdin, QIODevice::ReadOnly | QIODevice::Unbuffered);
+
connect(&notifier, SIGNAL(activated(int)), SLOT(readCommand()));
}
void Helper::readCommand()
{
QString command = readLine();
- if(!std::cin.good())
+ if(input.atEnd())
{
#ifdef DEBUG_KDE
std::cerr << "EOF, exiting." << std::endl;
@@ -639,11 +641,8 @@ QString Helper::getAppForProtocol(const QString& protocol)
QString Helper::readLine()
{
- std::string line;
- if(!std::getline(std::cin, line))
- return {};
-
- QString qline = QString::fromStdString(line);
+ QString qline = input.readLine();
+ qline.chop(1);
qline.replace("\\n", "\n");
qline.replace("\\" "\\", "\\");
return qline;
diff --git a/main.h b/main.h
index 29482d7..5709b29 100644
--- a/main.h
+++ b/main.h
@@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef MAIN_H
#define MAIN_H
+#include <QtCore/QFile>
#include <QtCore/QMimeType>
#include <QtCore/QSocketNotifier>
@@ -66,6 +67,7 @@ protected:
private slots:
void readCommand();
private:
+ QFile input;
QSocketNotifier notifier;
QStringList arguments;
bool arguments_read;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment