| Summary: | kdvi should read files from stdin with the - option | ||
|---|---|---|---|
| Product: | [Unmaintained] kdvi | Reporter: | Tristan Miller <psychonaut> |
| Component: | general | Assignee: | Stefan Kebekus <kebekus> |
| Status: | RESOLVED FIXED | ||
| Severity: | wishlist | ||
| Priority: | NOR | ||
| Version First Reported In: | unspecified | ||
| Target Milestone: | --- | ||
| Platform: | Slackware | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
|
Description
Tristan Miller
2005-12-01 19:05:49 UTC
Looks like it got submitted twice. *** This bug has been marked as a duplicate of 11749 *** wrong dup *** This bug has been marked as a duplicate of 117449 *** How is this a duplicate of Bug 117449? They're for different applications. You're right, of course, I misread it. SVN commit 485067 by whuss:
Implement the ability to read from standard input.
Code adapted from KGhostview.
BUG: 117450
M +53 -1 kviewshell.cpp
M +5 -0 kviewshell.h
M +21 -8 main.cpp
--- branches/work/kviewshell-0.7/kviewshell/shell/kviewshell.cpp #485066:485067
@@ -30,6 +30,7 @@
#include <kstandarddirs.h>
#include <kstatusbar.h>
#include <kstdaction.h>
+#include <ktempfile.h>
#include <kurldrag.h>
#include <qfileinfo.h>
@@ -48,7 +49,8 @@
KViewShell::KViewShell(const QString& defaultMimeType)
- : KParts::MainWindow()
+ : KParts::MainWindow(),
+ tmpFile(0)
{
// create the viewer part
@@ -146,6 +148,14 @@
KViewShell::~KViewShell()
{
writeSettings();
+
+ if (tmpFile)
+ {
+ tmpFile->setAutoDelete(true);
+ delete tmpFile;
+ tmpFile = 0;
+ }
+
delete view;
}
@@ -249,6 +259,48 @@
view->openURL(url);
}
+
+void KViewShell::openStdin()
+{
+ if (tmpFile)
+ {
+ tmpFile->setAutoDelete(true);
+ delete tmpFile;
+ }
+
+ tmpFile = new KTempFile;
+ tmpFile->setAutoDelete(true);
+
+ if (tmpFile->status() != 0 )
+ {
+ KMessageBox::error(this, i18n("Could not create temporary file: %1").arg(strerror(tmpFile->status())));
+ return;
+ }
+
+ QByteArray buf(BUFSIZ);
+ int read = 0;
+ int written = 0;
+ while ((read = fread(buf.data(), sizeof(char), buf.size(), stdin)) > 0)
+ {
+ written = tmpFile->file()->writeBlock(buf.data(), read);
+ if (read != written)
+ break;
+ kapp->processEvents();
+ }
+
+ if (read != 0)
+ {
+ KMessageBox::error(this, i18n("Could not open standard input stream: %1").arg(strerror(errno)));
+ return;
+ }
+
+ tmpFile->close();
+
+ if (view->openURL(KURL::fromPathOrURL(tmpFile->name())))
+ setCaption("stdin");
+}
+
+
void KViewShell::slotFullScreen()
{
if (fullScreenAction->isChecked()) {
--- branches/work/kviewshell-0.7/kviewshell/shell/kviewshell.h #485066:485067
@@ -7,6 +7,7 @@
#include <qstring.h>
class KRecentFilesAction;
+class KTempFile;
class KToggleAction;
class KURL;
class KViewPart_Iface;
@@ -26,6 +27,7 @@
public slots:
void openURL(const KURL&);
+ void openStdin();
void addRecentFile();
@@ -83,6 +85,9 @@
bool isStatusBarShownInNormalMode;
// ditto, for the toolbar
bool isToolBarShownInNormalMode;
+
+ // Used for storing data received from stdin
+ KTempFile* tmpFile;
};
--- branches/work/kviewshell-0.7/kviewshell/shell/main.cpp #485066:485067
@@ -103,6 +103,12 @@
return -1;
}
+ if (QString(args->arg(0)) == "-")
+ {
+ kdError(kvs::shell) << QString(I18N_NOOP("You can not read from standard input if you are using the '--unique' option.")) << endl;
+ return -1;
+ }
+
QString qualPath = QFileInfo(args->url(0).path()).absFilePath();
app.dcopClient()->attach();
@@ -172,16 +178,23 @@
if ( args->count() > 0 )
{
- KURL url = args->url(0);
- if (!url.hasRef() && args->isSet("goto"))
+ if (QString(args->arg(0)) == "-" )
{
- // If the url doesn't already has a reference part, add the
- // argument of --goto to the url as reference, to make the
- // KViewShell jump to this page.
- QString reference = args->getOption("goto");
- url.setHTMLRef(reference);
+ shell->openStdin();
}
- shell->openURL(url);
+ else
+ {
+ KURL url = args->url(0);
+ if (!url.hasRef() && args->isSet("goto"))
+ {
+ // If the url doesn't already has a reference part, add the
+ // argument of --goto to the url as reference, to make the
+ // KViewShell jump to this page.
+ QString reference = args->getOption("goto");
+ url.setHTMLRef(reference);
+ }
+ shell->openURL(url);
+ }
}
}
SVN commit 485069 by whuss:
Port of commit 485067
Implement the ability to read from standard input.
Code adapted from KGhostview.
CCBUG: 117450
M +55 -1 kviewshell.cpp
M +5 -0 kviewshell.h
M +21 -8 main.cpp
--- trunk/KDE/kdegraphics/kviewshell/shell/kviewshell.cpp #485068:485069
@@ -27,12 +27,15 @@
#include <kmimetype.h>
#include <kstatusbar.h>
#include <kstdaction.h>
+#include <ktempfile.h>
#include <QDragEnterEvent>
#include <QFileInfo>
#include <QKeyEvent>
#include <kglobal.h>
+#include <cerrno>
+
#include "kviewshell.moc"
#define StatusBar_ID_PageNr 1
@@ -41,7 +44,8 @@
KViewShell::KViewShell(const QString& defaultMimeType)
- : KParts::MainWindow()
+ : KParts::MainWindow(),
+ tmpFile(0)
{
// create the viewer part
@@ -138,6 +142,14 @@
KViewShell::~KViewShell()
{
writeSettings();
+
+ if (tmpFile)
+ {
+ tmpFile->setAutoDelete(true);
+ delete tmpFile;
+ tmpFile = 0;
+ }
+
delete view;
}
@@ -241,6 +253,48 @@
view->openURL(url);
}
+
+void KViewShell::openStdin()
+{
+ if (tmpFile)
+ {
+ tmpFile->setAutoDelete(true);
+ delete tmpFile;
+ }
+
+ tmpFile = new KTempFile;
+ tmpFile->setAutoDelete(true);
+
+ if (tmpFile->status() != 0 )
+ {
+ KMessageBox::error(this, i18n("Could not create temporary file: %1").arg(strerror(tmpFile->status())));
+ return;
+ }
+
+ QByteArray buf(BUFSIZ);
+ int read = 0;
+ int written = 0;
+ while ((read = fread(buf.data(), sizeof(char), buf.size(), stdin)) > 0)
+ {
+ written = tmpFile->file()->writeBlock(buf.data(), read);
+ if (read != written)
+ break;
+ kapp->processEvents();
+ }
+
+ if (read != 0)
+ {
+ KMessageBox::error(this, i18n("Could not open standard input stream: %1").arg(strerror(errno)));
+ return;
+ }
+
+ tmpFile->close();
+
+ if (view->openURL(KURL::fromPathOrURL(tmpFile->name())))
+ setCaption("stdin");
+}
+
+
void KViewShell::slotFullScreen()
{
if (fullScreenAction->isChecked()) {
--- trunk/KDE/kdegraphics/kviewshell/shell/kviewshell.h #485068:485069
@@ -7,6 +7,7 @@
#include <QString>
class KRecentFilesAction;
+class KTempFile;
class KToggleAction;
class KURL;
class KViewPart_Iface;
@@ -26,6 +27,7 @@
public slots:
void openURL(const KURL&);
+ void openStdin();
void addRecentFile();
@@ -83,6 +85,9 @@
bool isStatusBarShownInNormalMode;
// ditto, for the toolbar
bool isToolBarShownInNormalMode;
+
+ // Used for storing data received from stdin
+ KTempFile* tmpFile;
};
--- trunk/KDE/kdegraphics/kviewshell/shell/main.cpp #485068:485069
@@ -103,6 +103,12 @@
return -1;
}
+ if (QString(args->arg(0)) == "-")
+ {
+ kdError(kvs::shell) << QString(I18N_NOOP("You can not read from standard input if you are using the '--unique' option.")) << endl;
+ return -1;
+ }
+
QString qualPath = QFileInfo(args->url(0).path()).absoluteFilePath();
app.dcopClient()->attach();
@@ -174,16 +180,23 @@
if ( args->count() > 0 )
{
- KURL url = args->url(0);
- if (!url.hasRef() && args->isSet("goto"))
+ if (QString(args->arg(0)) == "-" )
{
- // If the url doesn't already has a reference part, add the
- // argument of --goto to the url as reference, to make the
- // KViewShell jump to this page.
- QString reference = args->getOption("goto");
- url.setHTMLRef(reference);
+ shell->openStdin();
}
- shell->openURL(url);
+ else
+ {
+ KURL url = args->url(0);
+ if (!url.hasRef() && args->isSet("goto"))
+ {
+ // If the url doesn't already has a reference part, add the
+ // argument of --goto to the url as reference, to make the
+ // KViewShell jump to this page.
+ QString reference = args->getOption("goto");
+ url.setHTMLRef(reference);
+ }
+ shell->openURL(url);
+ }
}
}
|