diff --git a/src/internfile/internfile.cpp b/src/internfile/internfile.cpp index 177c22d6..09d0b126 100644 --- a/src/internfile/internfile.cpp +++ b/src/internfile/internfile.cpp @@ -951,11 +951,23 @@ static string urltolocalpath(string url) // - The internfile temporary directory gets destroyed by its destructor // - The output temporary file which is held in a reference-counted // object and will be deleted when done with. +// This DOES NOT work with a non-internal file (because at least one conversion +// is always performed). bool FileInterner::idocToFile(TempFile& otemp, const string& tofile, RclConfig *cnf, const Rcl::Doc& idoc) { LOGDEB(("FileInterner::idocToFile\n")); - idoc.dump(); + // idoc.dump(); + + if (idoc.ipath.empty()) { + LOGDEB(("FileInterner::idocToFile: not a sub-document !\n")); + // We could do a copy here but it's much more complicated than + // it seems because the source is not necessarily a simple + // depending on the backend. Until we fix the Internfile + // constructor to not do the first conversion, it's much saner + // to just return an error + return false; + } // We set FIF_forPreview for consistency with the previous version // which determined this by looking at mtype!=null. Probably @@ -1004,6 +1016,7 @@ bool FileInterner::interntofile(TempFile& otemp, const string& tofile, } else { filename = tofile; } + int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600); if (fd < 0) { LOGERR(("FileInterner::interntofile: open(%s) failed errno %d\n", @@ -1018,6 +1031,7 @@ bool FileInterner::interntofile(TempFile& otemp, const string& tofile, return false; } close(fd); + if (tofile.empty()) otemp = temp; return true; diff --git a/src/qtgui/multisave.cpp b/src/qtgui/multisave.cpp index 26af1ea6..e6bf5108 100644 --- a/src/qtgui/multisave.cpp +++ b/src/qtgui/multisave.cpp @@ -90,10 +90,13 @@ void multiSave(QWidget *p, vector& docs) string utf8fn; it->getmeta(Rcl::Doc::keyfn, &utf8fn); string suffix = path_suffix(utf8fn); + LOGDEB(("Multisave: [%s] suff [%s]\n", utf8fn.c_str(), suffix.c_str())); if (suffix.empty() || suffix.size() > 10) { suffix = theconfig->getSuffixFromMimeType(it->mimetype); + LOGDEB(("Multisave: suff from config [%s]\n", suffix.c_str())); } - string simple = path_basename(utf8fn, suffix); + string simple = path_basename(utf8fn, string(".") + suffix); + LOGDEB(("Multisave: simple [%s]\n", simple.c_str())); if (simple.empty()) simple = "rclsave"; if (simple.size() > maxlen) { @@ -104,8 +107,8 @@ void multiSave(QWidget *p, vector& docs) ss << simple; if (vers) ss << "." << vers; - if (!suffix.empty()) - ss << suffix; + if (!suffix.empty()) + ss << "." << suffix; string fn = (const char *)QString::fromUtf8(ss.str().c_str()).toLocal8Bit(); diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 7dbec06d..936d008b 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -305,6 +305,8 @@ void RclMain::init() this, SLOT(startNativeViewer(Rcl::Doc))); connect(restable, SIGNAL(docSaveToFileClicked(Rcl::Doc)), this, SLOT(saveDocToFile(Rcl::Doc))); + connect(restable, SIGNAL(showSnippets(Rcl::Doc)), + this, SLOT(showSnippets(Rcl::Doc))); reslist->setRclMain(this, true); connect(this, SIGNAL(docSourceChanged(RefCntr)), diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index a043d83e..fb5424dc 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -981,7 +981,8 @@ void ResList::createPopupMenu(const QPoint& pos) Rcl::Doc doc; if (!getDoc(m_popDoc, doc)) return; - int options = 0; + + int options = ResultPopup::showSaveOne; if (m_ismainres) options |= ResultPopup::isMain; QMenu *popup = ResultPopup::create(this, options, m_source, doc); diff --git a/src/qtgui/respopup.cpp b/src/qtgui/respopup.cpp index 5dbd9750..f7163573 100644 --- a/src/qtgui/respopup.cpp +++ b/src/qtgui/respopup.cpp @@ -32,17 +32,31 @@ QMenu *create(QWidget *me, int opts, RefCntr source, Rcl::Doc& doc) { QMenu *popup = new QMenu(me); + LOGDEB(("ResultPopup::create: opts %x haspages %d %s %s\n", opts, + doc.haspages, source.isNull() ? + "Source is Null" : "Source not null", + source.isNull() ? "" : source->snippetsCapable() ? + "snippetsCapable" : "not snippetsCapable")); + string apptag; doc.getmeta(Rcl::Doc::keyapptg, &apptag); + popup->addAction(me->tr("&Preview"), me, SLOT(menuPreview())); + if (!theconfig->getMimeViewerDef(doc.mimetype, apptag, 0).empty()) { popup->addAction(me->tr("&Open"), me, SLOT(menuEdit())); } + popup->addAction(me->tr("Copy &File Name"), me, SLOT(menuCopyFN())); popup->addAction(me->tr("Copy &URL"), me, SLOT(menuCopyURL())); - if (!doc.ipath.empty()) + + if ((opts&showSaveOne) && !doc.ipath.empty()) popup->addAction(me->tr("&Write to File"), me, SLOT(menuSaveToFile())); + if ((opts&showSaveSel)) + popup->addAction(me->tr("Save selection to files"), + me, SLOT(menuSaveSelection())); + Rcl::Doc pdoc; if (source.isNotNull() && source->getEnclosing(doc, pdoc)) { popup->addAction(me->tr("Preview P&arent document/folder"), @@ -50,16 +64,19 @@ QMenu *create(QWidget *me, int opts, RefCntr source, Rcl::Doc& doc) popup->addAction(me->tr("&Open Parent document/folder"), me, SLOT(menuOpenParent())); } + if (opts & showExpand) popup->addAction(me->tr("Find &similar documents"), me, SLOT(menuExpand())); + if (doc.haspages && source.isNotNull() && source->snippetsCapable()) popup->addAction(me->tr("Open &Snippets window"), - me, SLOT(menuOpenSnippets())); + me, SLOT(menuShowSnippets())); if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc)) popup->addAction(me->tr("Show subdocuments / attachments"), me, SLOT(menuShowSubDocs())); + return popup; } diff --git a/src/qtgui/respopup.h b/src/qtgui/respopup.h index 03c3433e..b1141fe7 100644 --- a/src/qtgui/respopup.h +++ b/src/qtgui/respopup.h @@ -18,7 +18,8 @@ #define _RESPOPUP_H_INCLUDED_ namespace ResultPopup { - enum Options {showExpand = 0x1, showSubs = 0x2, isMain = 0x3}; + enum Options {showExpand = 0x1, showSubs = 0x2, isMain = 0x3, + showSaveOne = 0x4, showSaveSel = 0x8}; extern QMenu *create(QWidget *me, int opts, RefCntr source, Rcl::Doc& doc); diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index d949f313..76ba0d10 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -91,8 +91,7 @@ private: bool ResTablePager::append(const string& data, int, const Rcl::Doc&) { - m_parent->m_detail->moveCursor(QTextCursor::End, - QTextCursor::MoveAnchor); + m_parent->m_detail->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); m_parent->m_detail->textCursor().insertBlock(); m_parent->m_detail->insertHtml(QString::fromUtf8(data.c_str())); return true; @@ -139,11 +138,11 @@ ResTableDetailArea::ResTableDetailArea(ResTable* parent) void ResTableDetailArea::createPopupMenu(const QPoint& pos) { if (m_table && m_table->m_model && m_table->m_detaildocnum >= 0) { - QMenu *popup = - ResultPopup::create(m_table, m_table->m_ismainres ? - ResultPopup::showExpand : 0, - m_table->m_model->getDocSource(), - m_table->m_detaildoc); + int opts = m_table->m_ismainres ? ResultPopup::showExpand : 0; + opts |= ResultPopup::showSaveOne; + QMenu *popup = ResultPopup::create(m_table, opts, + m_table->m_model->getDocSource(), + m_table->m_detaildoc); popup->popup(mapToGlobal(pos)); } } @@ -483,7 +482,6 @@ void ResTable::init() tableView->setModel(m_model); tableView->setMouseTracking(true); tableView->setSelectionBehavior(QAbstractItemView::SelectRows); - tableView->setSelectionMode(QAbstractItemView::ContiguousSelection); tableView->setItemDelegate(new ResTableDelegate(this)); tableView->setContextMenuPolicy(Qt::CustomContextMenu); connect(tableView, SIGNAL(customContextMenuRequested(const QPoint&)), @@ -549,6 +547,15 @@ void ResTable::setRclMain(RclMain *m, bool ismain) { m_rclmain = m; m_ismainres = ismain; + + // We allow single selection only in the main table because this + // may have a mix of file-level docs and subdocs and multisave + // only works for subdocs + if (m_ismainres) + tableView->setSelectionMode(QAbstractItemView::SingleSelection); + else + tableView->setSelectionMode(QAbstractItemView::ExtendedSelection); + if (!m_ismainres) { connect(new QShortcut(closeKeySeq, this), SIGNAL (activated()), this, SLOT (close())); @@ -625,7 +632,8 @@ void ResTable::onTableView_currentChanged(const QModelIndex& index) m_detail->clear(); m_detaildocnum = index.row(); m_detaildoc = doc; - m_pager->displayDoc(theconfig, index.row(), doc, m_model->m_hdata); + m_pager->displayDoc(theconfig, index.row(), m_detaildoc, + m_model->m_hdata); } else { m_detaildocnum = -1; } @@ -757,11 +765,19 @@ void ResTable::createPopupMenu(const QPoint& pos) { LOGDEB(("ResTable::createPopupMenu: m_detaildocnum %d\n", m_detaildocnum)); if (m_detaildocnum >= 0 && m_model) { - QMenu *popup = - ResultPopup::create(this, m_ismainres? ResultPopup::isMain : 0, - m_model->getDocSource(), m_detaildoc); - popup->addAction(this->tr("Save selection to files"), - this, SLOT(menuSaveSelection())); + int opts = m_ismainres? ResultPopup::isMain : 0; + + int selsz = tableView->selectionModel()->selectedRows().size(); + + if (selsz == 1) { + opts |= ResultPopup::showSaveOne; + } else if (selsz > 1 && !m_ismainres) { + // We don't show save multiple for the main list because not all + // docs are necessary subdocs and multisave only works with those. + opts |= ResultPopup::showSaveSel; + } + QMenu *popup = ResultPopup::create(this, opts, m_model->getDocSource(), + m_detaildoc); popup->popup(mapToGlobal(pos)); } } @@ -849,6 +865,12 @@ void ResTable::menuExpand() emit docExpand(m_detaildoc); } +void ResTable::menuShowSnippets() +{ + if (m_detaildocnum >= 0) + emit showSnippets(m_detaildoc); +} + void ResTable::menuShowSubDocs() { if (m_detaildocnum >= 0) diff --git a/src/qtgui/restable.h b/src/qtgui/restable.h index e6032de6..588ee526 100644 --- a/src/qtgui/restable.h +++ b/src/qtgui/restable.h @@ -141,6 +141,7 @@ public slots: virtual void menuExpand(); virtual void menuPreviewParent(); virtual void menuOpenParent(); + virtual void menuShowSnippets(); virtual void menuShowSubDocs(); virtual void createHeaderPopupMenu(const QPoint&); virtual void deleteColumn(); @@ -158,6 +159,7 @@ signals: void headerClicked(); void docExpand(Rcl::Doc); void showSubDocs(Rcl::Doc); + void showSnippets(Rcl::Doc); friend class ResTablePager; friend class ResTableDetailArea; diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 73345b02..298279d8 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -279,7 +279,7 @@ string path_suffix(const string& s) string::size_type dotp = s.rfind('.'); if (dotp == string::npos) return string(); - return s.substr(dotp); + return s.substr(dotp+1); } string path_home() @@ -879,7 +879,7 @@ int main(int argc, const char **argv) pidfile.remove(); #endif -#if 1 +#if 0 if (argc != 2) { fprintf(stderr, "Usage: thumbpath \n"); exit(1); @@ -908,7 +908,16 @@ int main(int argc, const char **argv) exit(0); #endif +#if 1 + if (argc != 1) { + cerr << "Usage: trpathut " << endl; + exit(1); + } + string fn = *argv++;argc--; + string ext = path_suffix(fn); + cout << "Suffix: [" << ext << "]" << endl; return 0; +#endif } #endif // TEST_PATHUT