fix minor issues in multisave and popup menus
This commit is contained in:
parent
caffe8b6f3
commit
167c8a4286
@ -951,11 +951,23 @@ static string urltolocalpath(string url)
|
|||||||
// - The internfile temporary directory gets destroyed by its destructor
|
// - The internfile temporary directory gets destroyed by its destructor
|
||||||
// - The output temporary file which is held in a reference-counted
|
// - The output temporary file which is held in a reference-counted
|
||||||
// object and will be deleted when done with.
|
// 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,
|
bool FileInterner::idocToFile(TempFile& otemp, const string& tofile,
|
||||||
RclConfig *cnf, const Rcl::Doc& idoc)
|
RclConfig *cnf, const Rcl::Doc& idoc)
|
||||||
{
|
{
|
||||||
LOGDEB(("FileInterner::idocToFile\n"));
|
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
|
// We set FIF_forPreview for consistency with the previous version
|
||||||
// which determined this by looking at mtype!=null. Probably
|
// which determined this by looking at mtype!=null. Probably
|
||||||
@ -1004,6 +1016,7 @@ bool FileInterner::interntofile(TempFile& otemp, const string& tofile,
|
|||||||
} else {
|
} else {
|
||||||
filename = tofile;
|
filename = tofile;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600);
|
int fd = open(filename.c_str(), O_WRONLY|O_CREAT, 0600);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
LOGERR(("FileInterner::interntofile: open(%s) failed errno %d\n",
|
LOGERR(("FileInterner::interntofile: open(%s) failed errno %d\n",
|
||||||
@ -1018,6 +1031,7 @@ bool FileInterner::interntofile(TempFile& otemp, const string& tofile,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (tofile.empty())
|
if (tofile.empty())
|
||||||
otemp = temp;
|
otemp = temp;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -90,10 +90,13 @@ void multiSave(QWidget *p, vector<Rcl::Doc>& docs)
|
|||||||
string utf8fn;
|
string utf8fn;
|
||||||
it->getmeta(Rcl::Doc::keyfn, &utf8fn);
|
it->getmeta(Rcl::Doc::keyfn, &utf8fn);
|
||||||
string suffix = path_suffix(utf8fn);
|
string suffix = path_suffix(utf8fn);
|
||||||
|
LOGDEB(("Multisave: [%s] suff [%s]\n", utf8fn.c_str(), suffix.c_str()));
|
||||||
if (suffix.empty() || suffix.size() > 10) {
|
if (suffix.empty() || suffix.size() > 10) {
|
||||||
suffix = theconfig->getSuffixFromMimeType(it->mimetype);
|
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())
|
if (simple.empty())
|
||||||
simple = "rclsave";
|
simple = "rclsave";
|
||||||
if (simple.size() > maxlen) {
|
if (simple.size() > maxlen) {
|
||||||
@ -105,7 +108,7 @@ void multiSave(QWidget *p, vector<Rcl::Doc>& docs)
|
|||||||
if (vers)
|
if (vers)
|
||||||
ss << "." << vers;
|
ss << "." << vers;
|
||||||
if (!suffix.empty())
|
if (!suffix.empty())
|
||||||
ss << suffix;
|
ss << "." << suffix;
|
||||||
|
|
||||||
string fn =
|
string fn =
|
||||||
(const char *)QString::fromUtf8(ss.str().c_str()).toLocal8Bit();
|
(const char *)QString::fromUtf8(ss.str().c_str()).toLocal8Bit();
|
||||||
|
|||||||
@ -305,6 +305,8 @@ void RclMain::init()
|
|||||||
this, SLOT(startNativeViewer(Rcl::Doc)));
|
this, SLOT(startNativeViewer(Rcl::Doc)));
|
||||||
connect(restable, SIGNAL(docSaveToFileClicked(Rcl::Doc)),
|
connect(restable, SIGNAL(docSaveToFileClicked(Rcl::Doc)),
|
||||||
this, SLOT(saveDocToFile(Rcl::Doc)));
|
this, SLOT(saveDocToFile(Rcl::Doc)));
|
||||||
|
connect(restable, SIGNAL(showSnippets(Rcl::Doc)),
|
||||||
|
this, SLOT(showSnippets(Rcl::Doc)));
|
||||||
|
|
||||||
reslist->setRclMain(this, true);
|
reslist->setRclMain(this, true);
|
||||||
connect(this, SIGNAL(docSourceChanged(RefCntr<DocSequence>)),
|
connect(this, SIGNAL(docSourceChanged(RefCntr<DocSequence>)),
|
||||||
|
|||||||
@ -981,7 +981,8 @@ void ResList::createPopupMenu(const QPoint& pos)
|
|||||||
Rcl::Doc doc;
|
Rcl::Doc doc;
|
||||||
if (!getDoc(m_popDoc, doc))
|
if (!getDoc(m_popDoc, doc))
|
||||||
return;
|
return;
|
||||||
int options = 0;
|
|
||||||
|
int options = ResultPopup::showSaveOne;
|
||||||
if (m_ismainres)
|
if (m_ismainres)
|
||||||
options |= ResultPopup::isMain;
|
options |= ResultPopup::isMain;
|
||||||
QMenu *popup = ResultPopup::create(this, options, m_source, doc);
|
QMenu *popup = ResultPopup::create(this, options, m_source, doc);
|
||||||
|
|||||||
@ -32,17 +32,31 @@ QMenu *create(QWidget *me, int opts, RefCntr<DocSequence> source, Rcl::Doc& doc)
|
|||||||
{
|
{
|
||||||
QMenu *popup = new QMenu(me);
|
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;
|
string apptag;
|
||||||
doc.getmeta(Rcl::Doc::keyapptg, &apptag);
|
doc.getmeta(Rcl::Doc::keyapptg, &apptag);
|
||||||
|
|
||||||
popup->addAction(me->tr("&Preview"), me, SLOT(menuPreview()));
|
popup->addAction(me->tr("&Preview"), me, SLOT(menuPreview()));
|
||||||
|
|
||||||
if (!theconfig->getMimeViewerDef(doc.mimetype, apptag, 0).empty()) {
|
if (!theconfig->getMimeViewerDef(doc.mimetype, apptag, 0).empty()) {
|
||||||
popup->addAction(me->tr("&Open"), me, SLOT(menuEdit()));
|
popup->addAction(me->tr("&Open"), me, SLOT(menuEdit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
popup->addAction(me->tr("Copy &File Name"), me, SLOT(menuCopyFN()));
|
popup->addAction(me->tr("Copy &File Name"), me, SLOT(menuCopyFN()));
|
||||||
popup->addAction(me->tr("Copy &URL"), me, SLOT(menuCopyURL()));
|
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()));
|
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;
|
Rcl::Doc pdoc;
|
||||||
if (source.isNotNull() && source->getEnclosing(doc, pdoc)) {
|
if (source.isNotNull() && source->getEnclosing(doc, pdoc)) {
|
||||||
popup->addAction(me->tr("Preview P&arent document/folder"),
|
popup->addAction(me->tr("Preview P&arent document/folder"),
|
||||||
@ -50,16 +64,19 @@ QMenu *create(QWidget *me, int opts, RefCntr<DocSequence> source, Rcl::Doc& doc)
|
|||||||
popup->addAction(me->tr("&Open Parent document/folder"),
|
popup->addAction(me->tr("&Open Parent document/folder"),
|
||||||
me, SLOT(menuOpenParent()));
|
me, SLOT(menuOpenParent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts & showExpand)
|
if (opts & showExpand)
|
||||||
popup->addAction(me->tr("Find &similar documents"),
|
popup->addAction(me->tr("Find &similar documents"),
|
||||||
me, SLOT(menuExpand()));
|
me, SLOT(menuExpand()));
|
||||||
|
|
||||||
if (doc.haspages && source.isNotNull() && source->snippetsCapable())
|
if (doc.haspages && source.isNotNull() && source->snippetsCapable())
|
||||||
popup->addAction(me->tr("Open &Snippets window"),
|
popup->addAction(me->tr("Open &Snippets window"),
|
||||||
me, SLOT(menuOpenSnippets()));
|
me, SLOT(menuShowSnippets()));
|
||||||
|
|
||||||
if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc))
|
if ((opts & showSubs) && rcldb && rcldb->hasSubDocs(doc))
|
||||||
popup->addAction(me->tr("Show subdocuments / attachments"),
|
popup->addAction(me->tr("Show subdocuments / attachments"),
|
||||||
me, SLOT(menuShowSubDocs()));
|
me, SLOT(menuShowSubDocs()));
|
||||||
|
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,8 @@
|
|||||||
#define _RESPOPUP_H_INCLUDED_
|
#define _RESPOPUP_H_INCLUDED_
|
||||||
|
|
||||||
namespace ResultPopup {
|
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,
|
extern QMenu *create(QWidget *me, int opts,
|
||||||
RefCntr<DocSequence> source,
|
RefCntr<DocSequence> source,
|
||||||
Rcl::Doc& doc);
|
Rcl::Doc& doc);
|
||||||
|
|||||||
@ -91,8 +91,7 @@ private:
|
|||||||
|
|
||||||
bool ResTablePager::append(const string& data, int, const Rcl::Doc&)
|
bool ResTablePager::append(const string& data, int, const Rcl::Doc&)
|
||||||
{
|
{
|
||||||
m_parent->m_detail->moveCursor(QTextCursor::End,
|
m_parent->m_detail->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||||
QTextCursor::MoveAnchor);
|
|
||||||
m_parent->m_detail->textCursor().insertBlock();
|
m_parent->m_detail->textCursor().insertBlock();
|
||||||
m_parent->m_detail->insertHtml(QString::fromUtf8(data.c_str()));
|
m_parent->m_detail->insertHtml(QString::fromUtf8(data.c_str()));
|
||||||
return true;
|
return true;
|
||||||
@ -139,11 +138,11 @@ ResTableDetailArea::ResTableDetailArea(ResTable* parent)
|
|||||||
void ResTableDetailArea::createPopupMenu(const QPoint& pos)
|
void ResTableDetailArea::createPopupMenu(const QPoint& pos)
|
||||||
{
|
{
|
||||||
if (m_table && m_table->m_model && m_table->m_detaildocnum >= 0) {
|
if (m_table && m_table->m_model && m_table->m_detaildocnum >= 0) {
|
||||||
QMenu *popup =
|
int opts = m_table->m_ismainres ? ResultPopup::showExpand : 0;
|
||||||
ResultPopup::create(m_table, m_table->m_ismainres ?
|
opts |= ResultPopup::showSaveOne;
|
||||||
ResultPopup::showExpand : 0,
|
QMenu *popup = ResultPopup::create(m_table, opts,
|
||||||
m_table->m_model->getDocSource(),
|
m_table->m_model->getDocSource(),
|
||||||
m_table->m_detaildoc);
|
m_table->m_detaildoc);
|
||||||
popup->popup(mapToGlobal(pos));
|
popup->popup(mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -483,7 +482,6 @@ void ResTable::init()
|
|||||||
tableView->setModel(m_model);
|
tableView->setModel(m_model);
|
||||||
tableView->setMouseTracking(true);
|
tableView->setMouseTracking(true);
|
||||||
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
|
|
||||||
tableView->setItemDelegate(new ResTableDelegate(this));
|
tableView->setItemDelegate(new ResTableDelegate(this));
|
||||||
tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(tableView, SIGNAL(customContextMenuRequested(const QPoint&)),
|
connect(tableView, SIGNAL(customContextMenuRequested(const QPoint&)),
|
||||||
@ -549,6 +547,15 @@ void ResTable::setRclMain(RclMain *m, bool ismain)
|
|||||||
{
|
{
|
||||||
m_rclmain = m;
|
m_rclmain = m;
|
||||||
m_ismainres = ismain;
|
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) {
|
if (!m_ismainres) {
|
||||||
connect(new QShortcut(closeKeySeq, this), SIGNAL (activated()),
|
connect(new QShortcut(closeKeySeq, this), SIGNAL (activated()),
|
||||||
this, SLOT (close()));
|
this, SLOT (close()));
|
||||||
@ -625,7 +632,8 @@ void ResTable::onTableView_currentChanged(const QModelIndex& index)
|
|||||||
m_detail->clear();
|
m_detail->clear();
|
||||||
m_detaildocnum = index.row();
|
m_detaildocnum = index.row();
|
||||||
m_detaildoc = doc;
|
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 {
|
} else {
|
||||||
m_detaildocnum = -1;
|
m_detaildocnum = -1;
|
||||||
}
|
}
|
||||||
@ -757,11 +765,19 @@ void ResTable::createPopupMenu(const QPoint& pos)
|
|||||||
{
|
{
|
||||||
LOGDEB(("ResTable::createPopupMenu: m_detaildocnum %d\n", m_detaildocnum));
|
LOGDEB(("ResTable::createPopupMenu: m_detaildocnum %d\n", m_detaildocnum));
|
||||||
if (m_detaildocnum >= 0 && m_model) {
|
if (m_detaildocnum >= 0 && m_model) {
|
||||||
QMenu *popup =
|
int opts = m_ismainres? ResultPopup::isMain : 0;
|
||||||
ResultPopup::create(this, m_ismainres? ResultPopup::isMain : 0,
|
|
||||||
m_model->getDocSource(), m_detaildoc);
|
int selsz = tableView->selectionModel()->selectedRows().size();
|
||||||
popup->addAction(this->tr("Save selection to files"),
|
|
||||||
this, SLOT(menuSaveSelection()));
|
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));
|
popup->popup(mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -849,6 +865,12 @@ void ResTable::menuExpand()
|
|||||||
emit docExpand(m_detaildoc);
|
emit docExpand(m_detaildoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResTable::menuShowSnippets()
|
||||||
|
{
|
||||||
|
if (m_detaildocnum >= 0)
|
||||||
|
emit showSnippets(m_detaildoc);
|
||||||
|
}
|
||||||
|
|
||||||
void ResTable::menuShowSubDocs()
|
void ResTable::menuShowSubDocs()
|
||||||
{
|
{
|
||||||
if (m_detaildocnum >= 0)
|
if (m_detaildocnum >= 0)
|
||||||
|
|||||||
@ -141,6 +141,7 @@ public slots:
|
|||||||
virtual void menuExpand();
|
virtual void menuExpand();
|
||||||
virtual void menuPreviewParent();
|
virtual void menuPreviewParent();
|
||||||
virtual void menuOpenParent();
|
virtual void menuOpenParent();
|
||||||
|
virtual void menuShowSnippets();
|
||||||
virtual void menuShowSubDocs();
|
virtual void menuShowSubDocs();
|
||||||
virtual void createHeaderPopupMenu(const QPoint&);
|
virtual void createHeaderPopupMenu(const QPoint&);
|
||||||
virtual void deleteColumn();
|
virtual void deleteColumn();
|
||||||
@ -158,6 +159,7 @@ signals:
|
|||||||
void headerClicked();
|
void headerClicked();
|
||||||
void docExpand(Rcl::Doc);
|
void docExpand(Rcl::Doc);
|
||||||
void showSubDocs(Rcl::Doc);
|
void showSubDocs(Rcl::Doc);
|
||||||
|
void showSnippets(Rcl::Doc);
|
||||||
|
|
||||||
friend class ResTablePager;
|
friend class ResTablePager;
|
||||||
friend class ResTableDetailArea;
|
friend class ResTableDetailArea;
|
||||||
|
|||||||
@ -279,7 +279,7 @@ string path_suffix(const string& s)
|
|||||||
string::size_type dotp = s.rfind('.');
|
string::size_type dotp = s.rfind('.');
|
||||||
if (dotp == string::npos)
|
if (dotp == string::npos)
|
||||||
return string();
|
return string();
|
||||||
return s.substr(dotp);
|
return s.substr(dotp+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
string path_home()
|
string path_home()
|
||||||
@ -879,7 +879,7 @@ int main(int argc, const char **argv)
|
|||||||
pidfile.remove();
|
pidfile.remove();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
fprintf(stderr, "Usage: thumbpath <filepath> <size>\n");
|
fprintf(stderr, "Usage: thumbpath <filepath> <size>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -908,7 +908,16 @@ int main(int argc, const char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
if (argc != 1) {
|
||||||
|
cerr << "Usage: trpathut <filename>" << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
string fn = *argv++;argc--;
|
||||||
|
string ext = path_suffix(fn);
|
||||||
|
cout << "Suffix: [" << ext << "]" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TEST_PATHUT
|
#endif // TEST_PATHUT
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user