Bug 117450 - kdvi should read files from stdin with the - option
Summary: kdvi should read files from stdin with the - option
Status: RESOLVED FIXED
Alias: None
Product: kdvi
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: Slackware Linux
: NOR wishlist
Target Milestone: ---
Assignee: Stefan Kebekus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-01 19:05 UTC by Tristan Miller
Modified: 2005-12-02 20:35 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tristan Miller 2005-12-01 19:05:49 UTC
Version:            (using KDE KDE 3.5.0)
Installed from:    Slackware Packages

kghostview will read a postscript file from stdin when the - option is used.  Example:

$ antiword -pa4 -m8859-1 somefile.doc | kghostview -

However, kdvi will not do likewise for DVI files in stdin:

$ dviconcat foo.dvi bar.dvi | kdvi -

Please fix this so that kdvi will read from stdin.  Obviously, the file should not appear in the "Open recent" menu.
Comment 1 Rex Dieter 2005-12-01 19:37:14 UTC
Looks like it got submitted twice.

*** This bug has been marked as a duplicate of 11749 ***
Comment 2 Rex Dieter 2005-12-01 19:38:03 UTC
wrong dup
Comment 3 Rex Dieter 2005-12-01 19:38:19 UTC

*** This bug has been marked as a duplicate of 117449 ***
Comment 4 Tristan Miller 2005-12-01 19:48:42 UTC
How is this a duplicate of Bug 117449?  They're for different applications.
Comment 5 Rex Dieter 2005-12-01 21:05:54 UTC
You're right, of course, I misread it.
Comment 6 Wilfried Huss 2005-12-02 20:26:51 UTC
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);
+      }
     }
   }
 
Comment 7 Wilfried Huss 2005-12-02 20:35:46 UTC
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);
+      }
     }
   }