]> git.lyx.org Git - lyx.git/commitdiff
Georg Baum\'s no-tempdir patch
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 25 Feb 2004 12:00:53 +0000 (12:00 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 25 Feb 2004 12:00:53 +0000 (12:00 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8458 a592a061-630c-0410-9148-cb99ea01b6c8

35 files changed:
po/POTFILES.in
src/ChangeLog
src/buffer.C
src/buffer.h
src/cursor.C
src/cursor.h
src/exporter.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlPrint.C
src/frontends/controllers/ControlSendto.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/QPrefs.C
src/frontends/qt2/QPrefsDialog.C
src/frontends/qt2/ui/QPrefPathsModule.ui
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormPreferences.C
src/frontends/xforms/forms/form_preferences.fd
src/graphics/ChangeLog
src/graphics/GraphicsCacheItem.C
src/graphics/PreviewLoader.C
src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetgraphics.C
src/insets/insetinclude.C
src/lyx_main.C
src/lyxlex.h
src/lyxrc.C
src/lyxrc.h
src/lyxvc.C
src/paragraph.C
src/paragraph.h
src/support/ChangeLog
src/support/filename.h
src/support/filetools.C
src/support/filetools.h

index 9f0e10e39f0107d08ef37c1baea052605ce76f15..49d141d4848242dc3db71014524a3b3e069a1877 100644 (file)
@@ -5,12 +5,10 @@ src/Chktex.C
 src/LColor.C
 src/LaTeX.C
 src/MenuBackend.C
-src/ParagraphParameters.C
 src/buffer.C
 src/buffer_funcs.C
 src/bufferlist.C
 src/bufferparams.C
-src/bufferview_funcs.C
 src/converter.C
 src/debug.C
 src/exporter.C
@@ -195,8 +193,6 @@ src/paragraph.C
 src/paragraph_funcs.C
 src/rowpainter.C
 src/support/globbing.C
-src/support/path_defines.C
-src/tex2lyx/lengthcommon.C
 src/text.C
 src/text2.C
 src/text3.C
index 0179a4656a0bb4b301e63feab1ba54cc37e95acb..b93255d5a2d0042da420903caf56788042de869f 100644 (file)
@@ -1,3 +1,15 @@
+2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * lyxrc.C, buffer.C, exporter.C: use always a temp dir, ignore
+       use_tempdir in preferences
+       * buffer.C (readFile), lyxvc.C (getLogFile): check success of
+       tempfile creation
+       * lyx_main.C: ensure that tempdir is valid
+       * lyxlex.h: correct typo
+       * buffer.[Ch] (isMultiLingual), (isUnnamed): make const
+       * paragraph.[Ch] (isMultiLingual): make const
+       * cursor.[Ch] (openable): make const
+
 2004-02-20  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * text3.C: fixed LFUN_QUOTE and add lfun arguments single/double.
index 109ce4ee1274bca1e8c820171c2a4fbc55fc0db6..ca805619747a7121c7303d97b018f3283f95f732 100644 (file)
@@ -34,6 +34,7 @@
 #include "lyxtext.h"
 #include "lyxrc.h"
 #include "lyxvc.h"
+#include "lyx_main.h"
 #include "messages.h"
 #include "output.h"
 #include "output_docbook.h"
@@ -85,7 +86,7 @@ using lyx::support::atoi;
 using lyx::support::bformat;
 using lyx::support::ChangeExtension;
 using lyx::support::cmd_ret;
-using lyx::support::CreateBufferTmpDir;
+using lyx::support::createBufferTmpDir;
 using lyx::support::destroyDir;
 using lyx::support::FileInfo;
 using lyx::support::FileInfo;
@@ -190,8 +191,10 @@ Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
                text(0, 0)
 {
        lyxvc.buffer(&parent);
-       if (readonly_ || lyxrc.use_tempdir)
-               temppath = CreateBufferTmpDir();
+       temppath = createBufferTmpDir();
+       // FIXME: And now do something if temppath == string(), because we
+       // assume from now on that temppath points to a valid temp dir.
+       // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
 }
 
 
@@ -318,10 +321,7 @@ pair<Buffer::LogType, string> const Buffer::getLogName() const
        if (filename.empty())
                return make_pair(Buffer::latexlog, string());
 
-       string path = OnlyPath(filename);
-
-       if (lyxrc.use_tempdir || !IsDirWriteable(path))
-               path = temppath();
+       string const path = temppath();
 
        string const fname = AddName(path,
                                     OnlyFilename(ChangeExtension(filename,
@@ -596,6 +596,15 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
                                         filename));
        } else if (file_format < LYX_FORMAT) {
                string const tmpfile = tempName();
+               if (tmpfile.empty()) {
+                       Alert::error(_("Conversion failed"),
+                                    bformat(_("%1$s is from an earlier"
+                                             " version of LyX, but a temporary"
+                                             " file for converting it could"
+                                             " not be created."),
+                                             filename));
+                       return false;
+               }
                string command = LibFileSearch("lyx2lyx", "lyx2lyx");
                if (command.empty()) {
                        Alert::error(_("Conversion script not found"),
@@ -953,7 +962,7 @@ bool Buffer::isSGML() const
 
 void Buffer::makeLinuxDocFile(string const & fname,
                              OutputParams const & runparams,
-                             bool body_only )
+                              bool body_only)
 {
        ofstream ofs;
        if (!openFileWrite(ofs, fname))
@@ -1074,12 +1083,8 @@ int Buffer::runChktex()
 
        // get LaTeX-Filename
        string const name = getLatexName();
-       string path = filePath();
-
-       string const org_path = path;
-       if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
-               path = temppath();
-       }
+       string const path = temppath();
+       string const org_path = filePath();
 
        Path p(path); // path to LaTeX file
        message(_("Running chktex..."));
@@ -1272,10 +1277,10 @@ void Buffer::updateDocLang(Language const * nlang)
 }
 
 
-bool Buffer::isMultiLingual()
+bool Buffer::isMultiLingual() const
 {
-       ParIterator end = par_iterator_end();
-       for (ParIterator it = par_iterator_begin(); it != end; ++it)
+       ParConstIterator end = par_iterator_end();
+       for (ParConstIterator it = par_iterator_begin(); it != end; ++it)
                if (it->isMultiLingual(params()))
                        return true;
 
@@ -1424,7 +1429,7 @@ void Buffer::setUnnamed(bool flag)
 }
 
 
-bool Buffer::isUnnamed()
+bool Buffer::isUnnamed() const
 {
        return pimpl_->unnamed;
 }
index 431725bb378e8221346cf102014fc6a0e057839a..ccff3086d49c70a8a4cdf8bfa2339d2b0430ce34 100644 (file)
@@ -181,7 +181,7 @@ public:
        void setUnnamed(bool flag = true);
 
        ///
-       bool isUnnamed();
+       bool isUnnamed() const;
 
        /// Mark this buffer as dirty.
        void markDirty();
@@ -248,7 +248,7 @@ public:
        void updateDocLang(Language const * nlang);
 
        ///
-       bool isMultiLingual();
+       bool isMultiLingual() const;
 
        /// Does this mean that this is buffer local?
        limited_stack<Undo> & undostack();
index 99119245a59e194f1b03224d66898619d981de4c..6999d9ad00afa4b5dea94379319f165961c90392 100644 (file)
@@ -894,7 +894,7 @@ bool LCursor::isInside(InsetBase const * p)
 }
 
 
-bool LCursor::openable(MathAtom const & t)
+bool LCursor::openable(MathAtom const & t) const
 {
        if (!t->isActive())
                return false;
index 9fc092b126d09cf11fc932fd7ca46c690cdeac89..54ffb3400bc82ee1916dd295fbc9115c44d4ba45 100644 (file)
@@ -471,7 +471,7 @@ private:
        /// where in the curent cell does the macro name start?
        int macroNamePos();
        /// can we enter the inset?
-       bool openable(MathAtom const &);
+       bool openable(MathAtom const &) const;
 };
 
 #endif // LYXCURSOR_H
index a58c23e6a1cf4369f9fb64d9a6fb59998ae05ebe..a40fb40fb7584ddba3a986379bcf80ba6376860e 100644 (file)
@@ -85,8 +85,7 @@ bool Exporter::Export(Buffer * buffer, string const & format,
                backend_format = format;
 
        string filename = buffer->getLatexName(false);
-       if (!buffer->temppath().empty())
-               filename = AddName(buffer->temppath(), filename);
+       filename = AddName(buffer->temppath(), filename);
        filename = ChangeExtension(filename,
                                   formats.extension(backend_format));
 
index b6f08b2fca26232c6dfa565de603fd2c87cdcb7a..8f6a66fdd46a2750460b27f470bb52e11525f4f4 100644 (file)
@@ -1,3 +1,8 @@
+2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * ControlPrint.C, ControlSendto.C: use always a temp dir
+       * ControlSendto.C: check return value of buffer()->writeFile()
+
 2004-02-01  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * biblio.C (parseBibTeX): "=" -> '='
index 8c3fb6c829cba9c18c6e658d765a85c5c631859d..da85afa9c0aac3ded18768b604834284bd12484b 100644 (file)
@@ -170,10 +170,7 @@ void ControlPrint::apply()
        }
 
        // Push directory path.
-       string path = buffer()->filePath();
-       if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
-               path = buffer()->temppath();
-       }
+       string const path = buffer()->temppath();
        Path p(path);
 
        // there are three cases here:
index 7f53533d2eeeecc19eabb46ca235e9adda36ffad..3216d101dbf23b42eeba60fe63ecaf374b1cac4c 100644 (file)
@@ -120,10 +120,10 @@ void ControlSendto::apply()
        if (format_->name() == "lyx") {
                filename = ChangeExtension(buffer()->getLatexName(false),
                                           format_->extension());
-               if (!buffer()->temppath().empty())
-                       filename = AddName(buffer()->temppath(), filename);
+               filename = AddName(buffer()->temppath(), filename);
 
-               buffer()->writeFile(filename);
+               if (!buffer()->writeFile(filename))
+                       return;
 
        } else {
                Exporter::Export(buffer(), format_->name(), true, filename);
index 9f037d290551875bd223217f6bac5e4ae5494707..1f7458e033ca8012006530e4267e6d5509805c99 100644 (file)
@@ -1,3 +1,8 @@
+2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * QPrefs.C, QPrefsDialog.C, ui/QPrefPathsModule.ui: remove
+       use_tempdir
+
 2004-02-20  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * QDocument.C:
index 19d53f58b33800db762b331e8f0dc7b473318426..3c8c1072e4f59883ac89a9e1d5ace2604d00d3cb 100644 (file)
@@ -195,7 +195,6 @@ void QPrefs::apply()
        rc.document_path = fromqstr(pathsmod->workingDirED->text());
        rc.template_path = fromqstr(pathsmod->templateDirED->text());
        rc.backupdir_path = fromqstr(pathsmod->backupDirED->text());
-       rc.use_tempdir = pathsmod->tempDirCB->isChecked();
        rc.tempdir_path = fromqstr(pathsmod->tempDirED->text());
        // FIXME: should be a checkbox only
        rc.lyxpipes = fromqstr(pathsmod->lyxserverDirED->text());
@@ -499,7 +498,6 @@ void QPrefs::update_contents()
        pathsmod->workingDirED->setText(toqstr(rc.document_path));
        pathsmod->templateDirED->setText(toqstr(rc.template_path));
        pathsmod->backupDirED->setText(toqstr(rc.backupdir_path));
-       pathsmod->tempDirCB->setChecked(rc.use_tempdir);
        pathsmod->tempDirED->setText(toqstr(rc.tempdir_path));
        // FIXME: should be a checkbox only
        pathsmod->lyxserverDirED->setText(toqstr(rc.lyxpipes));
index f0532564a54d9dfc7a14355864eddaa64d27baba..169c9afb9d907f27103f8c61e8f107f0e495d6b2 100644 (file)
@@ -210,7 +210,6 @@ QPrefsDialog::QPrefsDialog(QPrefs * form)
        connect(pathsModule->workingDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
        connect(pathsModule->templateDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
        connect(pathsModule->backupDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
-       connect(pathsModule->tempDirCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
        connect(pathsModule->tempDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
        connect(pathsModule->lyxserverDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
        connect(spellcheckerModule->spellCommandCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
index 19c26fe4b50d7c20599b1c830adf875db92519af..dda3befe4c4328cda79cec3446eb1ebc69956ce6 100644 (file)
                     </property>
                 </widget>
                 <widget row="4"  column="0" >
-                    <class>QCheckBox</class>
+                    <class>QLabel</class>
                     <property stdset="1">
                         <name>name</name>
-                        <cstring>tempDirCB</cstring>
+                        <cstring>tempDirLA</cstring>
                     </property>
                     <property stdset="1">
                         <name>text</name>
-                        <string>&amp;Use temporary directory</string>
+                        <string>&amp;Temporary directory:</string>
+                    </property>
+                    <property>
+                        <name>buddy</name>
+                        <cstring>tempDirED</cstring>
                     </property>
                 </widget>
                 <widget row="3"  column="2" >
         </spacer>
     </vbox>
 </widget>
-<connections>
-    <connection>
-        <sender>tempDirCB</sender>
-        <signal>toggled(bool)</signal>
-        <receiver>tempDirED</receiver>
-        <slot>setEnabled(bool)</slot>
-    </connection>
-    <connection>
-        <sender>tempDirCB</sender>
-        <signal>toggled(bool)</signal>
-        <receiver>tempDirPB</receiver>
-        <slot>setEnabled(bool)</slot>
-    </connection>
-</connections>
 <tabstops>
     <tabstop>workingDirED</tabstop>
     <tabstop>workingDirPB</tabstop>
     <tabstop>backupDirPB</tabstop>
     <tabstop>lyxserverDirED</tabstop>
     <tabstop>lyxserverDirPB</tabstop>
-    <tabstop>tempDirCB</tabstop>
     <tabstop>tempDirED</tabstop>
     <tabstop>tempDirPB</tabstop>
 </tabstops>
index 612e492e1a51740a04c2a9e4efeb3f003a287a0e..6af2e995248459f4d99fd4b8aeff9b750f01a01a 100644 (file)
@@ -1,3 +1,7 @@
+2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * FormPreferences.C, forms/form_preferences.fd: remove use_tempdir
+
 2004-02-20  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * FormDocument.C:
index 3833d512e48969586a85188c4edd802d2f426b4f..db10c7371eb01f89e805eadc63e3e96cfbfd279b 100644 (file)
@@ -1825,17 +1825,10 @@ void FormPreferences::Paths::apply(LyXRC & rc)
 {
        rc.document_path = fl_get_input(dialog_->input_default_path);
        rc.template_path = fl_get_input(dialog_->input_template_path);
+       rc.tempdir_path  = fl_get_input(dialog_->input_temp_dir);
 
-       int button = fl_get_button(dialog_->check_use_temp_dir);
-       string str  = fl_get_input(dialog_->input_temp_dir);
-       if (!button)
-               str.erase();
-
-       rc.use_tempdir = button;
-       rc.tempdir_path = str;
-
-       button = fl_get_button(dialog_->check_last_files);
-       str = fl_get_input(dialog_->input_lastfiles);
+       int button = fl_get_button(dialog_->check_last_files);
+       string str = fl_get_input(dialog_->input_lastfiles);
        if (!button) str.erase();
 
        rc.check_lastfiles = button;
@@ -1880,7 +1873,6 @@ void FormPreferences::Paths::build()
        setPrehandler(dialog_->input_backup_path);
        setPrehandler(dialog_->input_serverpipe);
        setPrehandler(dialog_->input_temp_dir);
-       setPrehandler(dialog_->check_use_temp_dir);
 }
 
 
@@ -1891,8 +1883,6 @@ FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const
                return LyXRC::getDescription(LyXRC::RC_DOCUMENTPATH);
        if (ob == dialog_->input_template_path)
                return LyXRC::getDescription(LyXRC::RC_TEMPLATEPATH);
-       if (ob == dialog_->check_use_temp_dir)
-               return LyXRC::getDescription(LyXRC::RC_USETEMPDIR);
        if (ob == dialog_->input_temp_dir)
                return LyXRC::getDescription(LyXRC::RC_TEMPDIRPATH);
        if (ob == dialog_->check_last_files)
@@ -1918,11 +1908,6 @@ bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
        // !ob if function is called from Paths::update() to de/activate
        // objects,
        // otherwise the function is called by an xforms CB via input().
-       if (!ob || ob == dialog_->check_use_temp_dir) {
-               bool const enable = fl_get_button(dialog_->check_use_temp_dir);
-               setEnabled(dialog_->input_temp_dir, enable);
-       }
-
        if (!ob || ob == dialog_->check_last_files) {
                bool const enable = fl_get_button(dialog_->check_last_files);
                setEnabled(dialog_->input_lastfiles, enable);
@@ -2046,13 +2031,7 @@ void FormPreferences::Paths::update(LyXRC const & rc)
                      rc.make_backup);
        fl_set_input(dialog_->input_backup_path, str.c_str());
 
-       str.erase();
-       if (rc.use_tempdir)
-               str = rc.tempdir_path;
-
-       fl_set_button(dialog_->check_use_temp_dir,
-                     rc.use_tempdir);
-       fl_set_input(dialog_->input_temp_dir, str.c_str());
+       fl_set_input(dialog_->input_temp_dir, rc.tempdir_path.c_str());
 
        str.erase();
        if (rc.check_lastfiles)
index eea380d9d877439f7b6148a2ae43cced3c2d3e2f..a4c47e7a873ce90d52f95a0adbe14430f604d2db 100644 (file)
@@ -2024,7 +2024,7 @@ argument: 0
 Name: form_preferences_paths
 Width: 450
 Height: 350
-Number of Objects: 17
+Number of Objects: 16
 
 --------------------
 class: FL_BOX
@@ -2116,25 +2116,6 @@ name: button_template_path_browse
 callback: C_FormBaseInputCB
 argument: 0
 
---------------------
-class: FL_CHECKBUTTON
-type: PUSH_BUTTON
-box: 140 80 30 30
-boxtype: FL_NO_BOX
-colors: FL_COL1 FL_YELLOW
-alignment: FL_ALIGN_LEFT
-style: FL_NORMAL_STYLE
-size: FL_NORMAL_SIZE
-lcol: FL_BLACK
-label: Temp dir:|#d
-shortcut: 
-resize: FL_RESIZE_ALL
-gravity: FL_NoGravity FL_NoGravity
-name: check_use_temp_dir
-callback: C_FormBaseInputCB
-argument: 0
-       value: 1
-
 --------------------
 class: FL_INPUT
 type: NORMAL_INPUT
@@ -2145,7 +2126,7 @@ alignment: FL_ALIGN_LEFT
 style: FL_NORMAL_STYLE
 size: FL_NORMAL_SIZE
 lcol: FL_BLACK
-label: 
+label: Temp dir:|#d
 shortcut: 
 resize: FL_RESIZE_ALL
 gravity: FL_NoGravity FL_NoGravity
index 0a18e061b2c870deddec84f0b420be74cc74f899..b4d02c42082102a11146c4a7ce37f9ce2039b546 100644 (file)
@@ -1,3 +1,10 @@
+2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * GraphicsCacheItem.C (convertToDisplayFormat): unzip zipped files
+       to a temporary file
+       * PreviewLoader.C: use always a temp dir
+       * PreviewLoader.C: check successfull creation of LaTeX file
+
 2004-01-31  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * PreviewLoader.C (FindFirst): inherit from std::unary_function
index c2e9350947bb210767ada2c9693013fb5e1bca6e..59973327d441815b6bbf1ff202eb94fc5f7c8e6c 100644 (file)
@@ -36,6 +36,7 @@ using support::getExtFromContents;
 using support::tempName;
 using support::unlink;
 using support::unzipFile;
+using support::unzippedFileName;
 using support::zippedFile;
 
 using std::endl;
@@ -381,8 +382,19 @@ void CacheItem::Impl::convertToDisplayFormat()
        }
 
        // Make a local copy in case we unzip it
-       string const filename = zippedFile(filename_) ?
-               unzipFile(filename_) : filename_;
+       string filename;
+       if ((zipped_ = zippedFile(filename_))) {
+               unzipped_filename_ = tempName(string(), filename_);
+               if (unzipped_filename_.empty()) {
+                       setStatus(ErrorConverting);
+                       lyxerr[Debug::GRAPHICS]
+                               << "\tCould not create temporary file." << endl;
+                       return;
+               }
+               filename = unzipFile(filename_, unzipped_filename_);
+       } else
+               filename = filename_;
+
        string const displayed_filename = MakeDisplayPath(filename_);
        lyxerr[Debug::GRAPHICS] << "[GrahicsCacheItem::convertToDisplayFormat]\n"
                << "\tAttempting to convert image file: " << filename
@@ -412,6 +424,7 @@ void CacheItem::Impl::convertToDisplayFormat()
        remove_loaded_file_ = true;
 
        // Remove the temp file, we only want the name...
+       // FIXME: This is unsafe!
        unlink(to_file_base);
 
        // Connect a signal to this->imageConverted and pass this signal to
index 7e2b3ae3db4f2cc56bd82d496575eeefeda2fb4a..71ada4dba2baaf4e78f82e67928b82c5f1e8dfa5 100644 (file)
@@ -461,8 +461,7 @@ void PreviewLoader::Impl::startLoading()
        lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()" << endl;
 
        // As used by the LaTeX file and by the resulting image files
-       string const directory = buffer_.temppath().empty() ?
-               buffer_.filePath() : buffer_.temppath();
+       string const directory = buffer_.temppath();
 
        string const filename_base(unique_filename(directory));
 
@@ -477,6 +476,12 @@ void PreviewLoader::Impl::startLoading()
        string const latexfile = filename_base + ".tex";
 
        ofstream of(latexfile.c_str());
+       if (!of) {
+               lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()\n"
+                                       << "Unable to create LaTeX file\n"
+                                       << latexfile << endl;
+               return;
+       }
        of << "\\batchmode\n";
        dumpPreamble(of);
        of << "\n\\begin{document}\n";
index 655e9e264e6c503b9b17df24495454a673c356a6..953a9575d6c0bb536b51b4f9918250ea5d98ae81 100644 (file)
@@ -1,3 +1,13 @@
+2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * insetexternal.C, insetgraphics.C, insetinclude.C: use always a
+       temp dir
+       * insetinclude.C (latex): show a GUI warning if textclasses don't
+       match
+       * insetinclude.C: use mangledFilename() for temp files
+       * insetgraphics.C (readInsetGraphics): remove version check, since
+       the graphics inset has no own fileformat number anymore
+
 2004-02-20  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * insetquotes.[Ch]: added new member that allows direct access
index 3c5d14ea6598a7fe4e80a167eb4ad755fbb41911..9e27a11dfbf61ad910941d4e4c500b7fb1052788 100644 (file)
@@ -77,6 +77,7 @@ namespace external {
 TempName::TempName()
 {
        tempname_ = support::tempName(string(), "lyxext");
+       // FIXME: This is unsafe
        support::unlink(tempname_);
        // must have an extension for the converter code to work correctly.
        tempname_ += ".tmp";
@@ -685,8 +686,7 @@ int InsetExternal::latex(Buffer const & buf, ostream & os,
        // run through the LaTeX compiler.
        // If we're running through the LaTeX compiler, we should write the
        // generated files in the bufer's temporary directory.
-       bool const external_in_tmpdir =
-               lyxrc.use_tempdir && !buf.temppath().empty() && !runparams.nice;
+       bool const external_in_tmpdir = !runparams.nice;
 
        // If the template has specified a PDFLaTeX output, then we try and
        // use that.
index bb4a0cdfd0e749ca75136b3f5a35ffd1296e098b..6b12a172c8576f4ef7667c8bcaf07d72026119cb 100644 (file)
@@ -29,9 +29,6 @@ TODO
 
 /* NOTES:
  * Fileformat:
- * Current version is 1 (inset file format version), when changing it
- * it should be changed in the Write() function when writing in one place
- * and when reading one should change the version check and the error message.
  * The filename is kept in  the lyx file in a relative way, so as to allow
  * moving the document file and its images with no problem.
  *
@@ -281,18 +278,7 @@ void InsetGraphics::readInsetGraphics(LyXLex & lex, string const & bufpath)
                        continue;
                } else if (token == "\\end_inset") {
                        finished = true;
-               } else if (token == "FormatVersion") {
-                       lex.next();
-                       int version = lex.getInteger();
-                       if (version > VersionNumber)
-                               lyxerr
-                               << "This document was created with a newer Graphics widget"
-                               ", You should use a newer version of LyX to read this"
-                               " file."
-                               << endl;
-                       // TODO: Possibly open up a dialog?
-               }
-               else {
+               } else {
                        if (!params_.Read(lex, token, bufpath))
                                lyxerr << "Unknown token, " << token << ", skipping."
                                        << std::endl;
@@ -469,9 +455,6 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
        lyxerr[Debug::GRAPHICS]
                << "\t we have: from " << from << " to " << to << '\n';
 
-       if (from == to && !lyxrc.use_tempdir)
-               return stripExtensionIfPossible(orig_file, to);
-
        // We're going to be running the exported buffer through the LaTeX
        // compiler, so must ensure that LaTeX can cope with the graphics
        // file format.
@@ -480,16 +463,14 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
                << "\tthe orig file is: " << orig_file << endl;
 
        bool conversion_needed = true;
-       if (lyxrc.use_tempdir) {
-               CopyStatus status;
-               boost::tie(status, temp_file) =
+       CopyStatus status;
+       boost::tie(status, temp_file) =
                        copyToDirIfNeeded(orig_file, buf.temppath());
 
-               if (status == FAILURE)
-                       return orig_file;
-               else if (status == IDENTICAL_CONTENTS)
-                       conversion_needed = false;
-       }
+       if (status == FAILURE)
+               return orig_file;
+       else if (status == IDENTICAL_CONTENTS)
+               conversion_needed = false;
 
        if (from == to)
                return stripExtensionIfPossible(temp_file, to);
@@ -515,7 +496,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
                << "\tto_file_base = " << to_file_base << '\n'
                << "\t from " << from << " to " << to << '\n';
 
-       // if no special converter defined, than we take the default one
+       // if no special converter defined, then we take the default one
        // from ImageMagic: convert from:inname.from to:outname.to
        if (!converters.convert(&buf, temp_file, to_file_base, from, to)) {
                string const command =
index ca9155c5d0db97f458160839c49d28c054e05f8c..adc479b396a5e1e5de9baf9a70b2aecbb1b4a9e7 100644 (file)
@@ -28,6 +28,7 @@
 #include "metricsinfo.h"
 #include "outputparams.h"
 
+#include "frontends/Alert.h"
 #include "frontends/LyXView.h"
 #include "frontends/Painter.h"
 
@@ -36,6 +37,7 @@
 #include "insets/render_preview.h"
 
 #include "support/FileInfo.h"
+#include "support/filename.h"
 #include "support/filetools.h"
 #include "support/lstrings.h" // contains
 #include "support/tostr.h"
 #include "support/std_sstream.h"
 
 using lyx::support::AddName;
+using lyx::support::bformat;
 using lyx::support::ChangeExtension;
 using lyx::support::contains;
 using lyx::support::FileInfo;
+using lyx::support::FileName;
 using lyx::support::GetFileContents;
 using lyx::support::IsFileReadable;
 using lyx::support::IsLyXFilename;
@@ -307,30 +311,25 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
        if (loadIfNeeded(buffer, params_)) {
                Buffer * tmp = bufferlist.getBuffer(included_file);
 
-               // FIXME: this should be a GUI warning
                if (tmp->params().textclass != buffer.params().textclass) {
-                       lyxerr << "WARNING: Included file `"
-                              << MakeDisplayPath(included_file)
-                              << "' has textclass `"
-                              << tmp->params().getLyXTextClass().name()
-                              << "' while parent file has textclass `"
-                              << buffer.params().getLyXTextClass().name()
-                              << "'." << endl;
+                       string text = bformat(_("Included file `%1$s'\n"
+                                               "has textclass `%2$s'\n"
+                                               "while parent file has textclass `%3$s'."),
+                                             MakeDisplayPath(included_file),
+                                             tmp->params().getLyXTextClass().name(),
+                                             buffer.params().getLyXTextClass().name());
+                       Alert::warning(_("Different textclasses"), text);
                        //return 0;
                }
 
                // write it to a file (so far the complete file)
                string writefile = ChangeExtension(included_file, ".tex");
 
-               if (!buffer.temppath().empty() && !runparams.nice) {
-                       incfile = subst(incfile, '/','@');
-#ifdef __EMX__
-                       incfile = subst(incfile, ':', '$');
-#endif
-                       writefile = AddName(buffer.temppath(), incfile);
-               } else
-                       writefile = included_file;
-               writefile = ChangeExtension(writefile, ".tex");
+               if (!runparams.nice) {
+                       incfile = FileName(writefile).mangledFilename();
+                       writefile = MakeAbsPath(incfile, buffer.temppath());
+               }
+
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
@@ -388,15 +387,16 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os,
                Buffer * tmp = bufferlist.getBuffer(included_file);
 
                // write it to a file (so far the complete file)
-               string writefile = ChangeExtension(included_file, ".sgml");
-               if (!buffer.temppath().empty() && !runparams.nice) {
-                       incfile = subst(incfile, '/','@');
-                       writefile = AddName(buffer.temppath(), incfile);
-               } else
+               string writefile;
+               if (IsLyXFilename(included_file))
+                       writefile = ChangeExtension(included_file, ".sgml");
+               else
                        writefile = included_file;
 
-               if (IsLyXFilename(included_file))
-                       writefile = ChangeExtension(writefile, ".sgml");
+               if (!runparams.nice) {
+                       incfile = FileName(writefile).mangledFilename();
+                       writefile = MakeAbsPath(incfile, buffer.temppath());
+               }
 
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
@@ -431,14 +431,16 @@ int InsetInclude::docbook(Buffer const & buffer, ostream & os,
                Buffer * tmp = bufferlist.getBuffer(included_file);
 
                // write it to a file (so far the complete file)
-               string writefile = ChangeExtension(included_file, ".sgml");
-               if (!buffer.temppath().empty() && !runparams.nice) {
-                       incfile = subst(incfile, '/','@');
-                       writefile = AddName(buffer.temppath(), incfile);
-               } else
-                       writefile = included_file;
+               string writefile;
                if (IsLyXFilename(included_file))
-                       writefile = ChangeExtension(writefile, ".sgml");
+                       writefile = ChangeExtension(included_file, ".sgml");
+               else
+                       writefile = included_file;
+
+               if (!runparams.nice) {
+                       incfile = FileName(writefile).mangledFilename();
+                       writefile = MakeAbsPath(incfile, buffer.temppath());
+               }
 
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
@@ -468,19 +470,15 @@ void InsetInclude::validate(LaTeXFeatures & features) const
        string const included_file = includedFilename(buffer, params_);
 
        if (IsLyXFilename(included_file))
-               writefile = ChangeExtension(writefile, ".sgml");
-       else if (!buffer.temppath().empty() &&
-                !features.nice() &&
-                !isVerbatim(params_)) {
-               incfile = subst(incfile, '/','@');
-#ifdef __EMX__
-// FIXME: It seems that the following is necessary (see latex() above)
-//             incfile = subst(incfile, ':', '$');
-#endif
-               writefile = AddName(buffer.temppath(), incfile);
-       } else
+               writefile = ChangeExtension(included_file, ".sgml");
+       else
                writefile = included_file;
 
+       if (!features.nice() && !isVerbatim(params_)) {
+               incfile = FileName(writefile).mangledFilename();
+               writefile = MakeAbsPath(incfile, buffer.temppath());
+       }
+
        features.includeFile(include_label, writefile);
 
        if (isVerbatim(params_))
index 53f614750ee59a75907cf2487365eb43b95093ec..7608131af2d8c26baa10bd86dd9faba35edf7ba6 100644 (file)
@@ -58,7 +58,7 @@ using lyx::support::AddName;
 using lyx::support::AddPath;
 using lyx::support::bformat;
 using lyx::support::createDirectory;
-using lyx::support::CreateLyXTmpDir;
+using lyx::support::createLyXTmpDir;
 using lyx::support::FileInfo;
 using lyx::support::FileSearch;
 using lyx::support::GetEnv;
@@ -390,7 +390,21 @@ void LyX::init(bool gui)
        if (lyxerr.debugging(Debug::LYXRC))
                lyxrc.print();
 
-       os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path));
+       os::setTmpDir(createLyXTmpDir(lyxrc.tempdir_path));
+       if (os::getTmpDir().empty()) {
+               Alert::error(_("Could not create temporary directory"),
+                            bformat(_("Could not create a temporary directory in\n"
+                                      "%1$s. Make sure that this\n"
+                                      "path exists and is writable and try again."),
+                                    lyxrc.tempdir_path));
+               // createLyXTmpDir() tries sufficiently hard to create a
+               // usable temp dir, so the probability to come here is
+               // close to zero. We therefore don't try to overcome this
+               // problem with e.g. asking the user for a new path and
+               // trying again but simply exit.
+               exit(EXIT_FAILURE);
+       }
+
        if (lyxerr.debugging(Debug::INIT)) {
                lyxerr << "LyX tmp dir: `" << os::getTmpDir() << '\'' << endl;
        }
index 41da5297898f521ada2011e0e6a43def3d9b9df3..8feb0094a65d871d9b4c032f46b714c78210ba10 100644 (file)
@@ -155,7 +155,7 @@ private:
     This is needed to ensure that the pop is done upon exit from methods
     with more than one exit point or that can return as a response to
     exceptions.
-    @autor Lgb
+    @author Lgb
 */
 struct pushpophelper {
        ///
index 24c940267bd087b83c3a487923269c46bcb43466..13911fdc68fa0b7b33ca1389d97214bace87edc4 100644 (file)
@@ -156,6 +156,7 @@ keyword_item lyxrcTags[] = {
        // compatibility with versions older than 1.4.0 only
        { "\\use_pspell", LyXRC::RC_USE_SPELL_LIB },
        { "\\use_spell_lib", LyXRC::RC_USE_SPELL_LIB },
+       // compatibility with versions older than 1.4.0 only
        { "\\use_tempdir", LyXRC::RC_USETEMPDIR },
        { "\\user_email", LyXRC::RC_USER_EMAIL },
        { "\\user_name", LyXRC::RC_USER_NAME },
@@ -197,7 +198,6 @@ void LyXRC::setDefaults() {
        print_paper_dimension_flag = "-T";
        document_path.erase();
        tempdir_path = "/tmp";
-       use_tempdir = true;
        ps_command = "gs";
        view_dvi_paper_option.erase();
        default_papersize = PAPER_USLETTER;
@@ -657,7 +657,7 @@ int LyXRC::read(string const & filename)
 
                case RC_USETEMPDIR:
                        if (lexrc.next()) {
-                               use_tempdir = lexrc.getBool();
+                               lyxerr << "Ignoring obsolete use_tempdir flag." << endl;
                        }
                        break;
 
@@ -1524,9 +1524,7 @@ void LyXRC::output(ostream & os) const
                        os << "\\tempdir_path \"" << tempdir_path << "\"\n";
                }
        case RC_USETEMPDIR:
-               if (use_tempdir != system_lyxrc.use_tempdir) {
-                       os << "\\use_tempdir " << tostr(use_tempdir) << '\n';
-               }
+               // Ignore it
        case RC_ASCII_LINELEN:
                if (ascii_linelen != system_lyxrc.ascii_linelen) {
                        os << "\\ascii_linelen " << ascii_linelen << '\n';
@@ -1904,10 +1902,6 @@ string const LyXRC::getDescription(LyXRCTags tag)
                str = _("LyX will place its temporary directories in this path. They will be deleted when you quit LyX.");
                break;
 
-       case RC_USETEMPDIR:
-               str = _("Select if you wish to use a temporary directory structure to store temporary TeX output.");
-               break;
-
        case RC_LASTFILES:
                str = _("The file where the last-files information should be stored.");
                break;
index d9240392535b000a34642bd257d9b63a3284cf2a..019aa61a901565af339a955d2263654901837486 100644 (file)
@@ -206,8 +206,6 @@ enum LyXRCTags {
        ///
        std::string tempdir_path;
        ///
-       bool use_tempdir;
-       ///
        bool auto_region_delete;
        /// flag telling whether lastfiles should be checked for existance
        bool auto_reset_options;
index 21c934f102ea9ccb80b153ec6980722a9f56ede0..039e4554356281cec5228e9dcd7a97f6502f6721 100644 (file)
@@ -223,6 +223,11 @@ string const LyXVC::getLogFile() const
                return string();
 
        string tmpf = tempName(string(), "lyxvclog");
+       if (tmpf.empty()) {
+               lyxerr[Debug::LYXVC] << "Could not generate logfile "
+                                    << tmpf << endl;
+               return string();
+       }
        lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
        vcs->getLog(tmpf);
        return tmpf;
index b46a5a2384243732d5045d328a412daabbc23b5e..71df78078a54f9dde82c74f4ed438d2f6de090e4 100644 (file)
@@ -1556,7 +1556,7 @@ void Paragraph::changeLanguage(BufferParams const & bparams,
 }
 
 
-bool Paragraph::isMultiLingual(BufferParams const & bparams)
+bool Paragraph::isMultiLingual(BufferParams const & bparams) const
 {
        Language const * doc_language = bparams.language;
        Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
index b7324920c78dcf1db78ba6215663c8802d313b19..28067bd2c2e300a52c61f6ab92f4710f541bffac 100644 (file)
@@ -80,7 +80,7 @@ public:
        void changeLanguage(BufferParams const & bparams,
                            Language const * from, Language const * to);
        ///
-       bool isMultiLingual(BufferParams const &);
+       bool isMultiLingual(BufferParams const &) const;
 
        ///
        std::string const asString(Buffer const &,
index 1047ccd03d3122aa6540b73af99361cb323960a9..afa4bc315383d309307a4a5352253d62b67107da 100644 (file)
@@ -1,3 +1,13 @@
+2004-02-21  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * filetools.[Ch] (CreateBufferTmpDir): rename to createBufferTmpDir,
+       remove pathfor argument
+       * filetools.[Ch] (CreateLyXTmpDir): rename to createLyXTmpDir, try
+       harder to create a usable temp dir
+       * filetools.C (CreateTmpDir): rename to createTmpDir
+       filetools.[Ch] (unzipFile): add argument for output filename
+       * filename.h: fix doxygen warning
+
 2004-02-01  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * lstrings.h (contains_functor): delete
index 4085c51fef0341705a1dbf82ba407a15ab136799..f019fde922b846fae7dc58d8f101d5d2616b79f4 100644 (file)
@@ -22,7 +22,7 @@ namespace support {
 class FileName {
 public:
        FileName();
-       /** \param filename the file in question. Must have an absolute path.
+       /** \param abs_filename the file in question. Must have an absolute path.
         *  \param save_abs_path how is the file to be output to file?
         */
        FileName(std::string const & abs_filename, bool save_abs_path = true);
index a30d50db1336be25ad7d90d3fcefad6b8d9da5e0..ccf6d560cec498ef8f0a3a49463438567289ba4a 100644 (file)
@@ -440,11 +440,11 @@ int DeleteAllFilesInDir(string const & path)
 }
 
 
-string const CreateTmpDir(string const & tempdir, string const & mask)
+string const createTmpDir(string const & tempdir, string const & mask)
 {
        lyxerr[Debug::FILES]
-               << "CreateTmpDir: tempdir=`" << tempdir << "'\n"
-               << "CreateTmpDir:    mask=`" << mask << '\'' << endl;
+               << "createTmpDir: tempdir=`" << tempdir << "'\n"
+               << "createTmpDir:    mask=`" << mask << '\'' << endl;
 
        string const tmpfl(tempName(tempdir, mask));
        // lyx::tempName actually creates a file to make sure that it
@@ -453,8 +453,11 @@ string const CreateTmpDir(string const & tempdir, string const & mask)
        // safe because of the gap between unlink and mkdir. (Lgb)
        unlink(tmpfl);
 
-       if (tmpfl.empty() || mkdir(tmpfl, 0700))
+       if (tmpfl.empty() || mkdir(tmpfl, 0700)) {
+               lyxerr << "LyX could not create the temporary directory '"
+                      << tmpfl << "'" << endl;
                return string();
+       }
 
        return MakeAbsPath(tmpfl);
 }
@@ -477,36 +480,47 @@ int destroyDir(string const & tmpdir)
 }
 
 
-string const CreateBufferTmpDir(string const & pathfor)
+string const createBufferTmpDir()
 {
        static int count;
-       static string const tmpdir(pathfor.empty() ? os::getTmpDir() : pathfor);
        // We are in our own directory.  Why bother to mangle name?
        // In fact I wrote this code to circumvent a problematic behaviour (bug?)
        // of EMX mkstemp().
-       string const tmpfl = tmpdir + "/lyx_tmpbuf" + tostr(count++);
+       string const tmpfl = os::getTmpDir() + "/lyx_tmpbuf" + tostr(count++);
        if (mkdir(tmpfl, 0777)) {
+               lyxerr << "LyX could not create the temporary directory '"
+                      << tmpfl << "'" << endl;
                return string();
        }
        return tmpfl;
 }
 
 
-string const CreateLyXTmpDir(string const & deflt)
+string const createLyXTmpDir(string const & deflt)
 {
-       if ((!deflt.empty()) && (deflt  != "/tmp")) {
+       if (!deflt.empty() && deflt != "/tmp") {
                if (mkdir(deflt, 0777)) {
+                       if (IsDirWriteable(deflt))
+                               // deflt could not be created because it
+                               // did exist already, so let's create our own
+                               // dir inside deflt.
 #ifdef __EMX__
-               Path p(user_lyxdir());
+                               Path p(user_lyxdir());
+#endif
+                               return createTmpDir(deflt, "lyx_tmpdir");
+                       else
+                               // some other error occured.
+#ifdef __EMX__
+                               Path p(user_lyxdir());
 #endif
-                       return CreateTmpDir(deflt, "lyx_tmpdir");
+                               return createTmpDir("/tmp", "lyx_tmpdir");
                } else
                        return deflt;
        } else {
 #ifdef __EMX__
                Path p(user_lyxdir());
 #endif
-               return CreateTmpDir("/tmp", "lyx_tmpdir");
+               return createTmpDir("/tmp", "lyx_tmpdir");
        }
 }
 
@@ -1080,9 +1094,10 @@ string const unzippedFileName(string const & zipped_file)
 }
 
 
-string const unzipFile(string const & zipped_file)
+string const unzipFile(string const & zipped_file, string const & unzipped_file)
 {
-       string  const tempfile = unzippedFileName(zipped_file);
+       string const tempfile = unzipped_file.empty() ?
+               unzippedFileName(zipped_file) : unzipped_file;
        // Run gunzip
        string const command = "gunzip -c " + zipped_file + " > " + tempfile;
        Systemcall one;
index 1a9e5217b78e3b16fa1a3140291b1c49245394c6..b145082dd0591722d1b796c0d28b824fdbc3825f 100644 (file)
@@ -22,14 +22,19 @@ namespace support {
 /// remove directory and all contents, returns 0 on success
 int destroyDir(std::string const & tmpdir);
 
-///
-std::string const CreateBufferTmpDir(std::string const & pathfor = std::string());
+/// Creates the per buffer temporary directory
+std::string const createBufferTmpDir();
 
 /// Creates directory. Returns true on success
 bool createDirectory(std::string const & name, int permissions);
 
-///
-std::string const CreateLyXTmpDir(std::string const & deflt);
+/** Creates the global LyX temp dir.
+  \p deflt can be an existing directory name. In this case a new directory
+  inside \p deflt is created. If \p deflt does not exist yet, \p deflt is
+  created and used as the temporary directory.
+  \return the tmp dir name or string() if something went wrong.
+ */
+std::string const createLyXTmpDir(std::string const & deflt);
 
 /** Find file by searching several directories.
   Uses a string of paths separated by ";"s to find a file to open.
@@ -141,11 +146,18 @@ std::string const getExtFromContents(std::string const & name);
 /// check for zipped file
 bool zippedFile(std::string const & name);
 
-/// \return the name that LyX will give to the unzipped file.
+/** \return the name that LyX will give to the unzipped file \p zipped_file
+  if the second argument of unzipFile() is empty.
+ */
 std::string const unzippedFileName(std::string const & zipped_file);
 
-/// unzip a file
-std::string const unzipFile(std::string const & zipped_file);
+/** Unzip \p zipped_file.
+  The unzipped file is named \p unzipped_file if \p unzipped_file is not
+  empty, and unzippedFileName(\p zipped_file) otherwise.
+  Will overwrite an already existing unzipped file without warning.
+ */
+std::string const unzipFile(std::string const & zipped_file,
+                            std::string const & unzipped_file = std::string());
 
 /// Returns true is path is absolute
 bool AbsolutePath(std::string const & path);