summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/packagemanagercore.cpp
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2020-05-08 08:42:53 +0300
committerKatja Marttila <katja.marttila@qt.io>2020-05-15 13:07:22 +0300
commit20f1400a11837005f0904f2c7cdb40dcd4d5b669 (patch)
tree366d4f8ba0b3ffd03d0a5ba06ef0a66961d78d32 /src/libs/installer/packagemanagercore.cpp
parent7f33b7b83320f8d6c9cb40f7d5d9d9842a22e8f8 (diff)
CLI: Add option to read arbitrary user input
Added new readConsoleLine() function which can be used to read user input from console. Function can be only called when command line instance is used without gui. Task-number: QTIFW-1631 Change-Id: Ic856f4bafc4a8d469d3fe497b4e0321e104df499 Reviewed-by: Tarja Sundqvist <tarja.sundqvist@qt.io> Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'src/libs/installer/packagemanagercore.cpp')
-rw-r--r--src/libs/installer/packagemanagercore.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 14d7114f6..bb754f568 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -878,6 +878,29 @@ QString PackageManagerCore::readFile(const QString &filePath, const QString &cod
}
/*!
+ * Prints \a title to console and reads console input. Function will halt the
+ * installer and wait for user input. Returns a line which user has typed into
+ * console. The maximum allowed line length is set to \a maxlen. If the stream
+ * contains lines longer than this, then the line will be split after maxlen
+ * characters. If \a maxlen is 0, the line can be of any length.
+ *
+ * \note Can be only called when installing from command line instance without GUI.
+ *
+ * \sa {installer::readConsoleLine}{installer.readConsoleLine}
+ */
+QString PackageManagerCore::readConsoleLine(const QString &title, qint64 maxlen) const
+{
+ if (!isCommandLineInstance())
+ return QString();
+ if (!title.isEmpty())
+ qDebug() << title;
+ QTextStream stream(stdin);
+ QString input;
+ stream.readLineInto(&input, maxlen);
+ return input;
+}
+
+/*!
Checks whether the target directory \a targetDirectory exists and has contents:
\list
\li Returns \c true if the directory exists and is empty.