[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klflibbrowser.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * file klflibbrowser.cpp
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klflibbrowser.cpp 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #include <QDebug>
25 #include <QFile>
26 #include <QMenu>
27 #include <QAction>
28 #include <QEvent>
29 #include <QKeyEvent>
30 #include <QShortcut>
31 #include <QMessageBox>
32 #include <QSignalMapper>
33 #include <QLineEdit>
34 #include <QProgressDialog>
35 #include <QPushButton>
36 #include <QApplication>
37 #include <QClipboard>
38 #include <QDesktopServices>
39 
40 #include "klfconfig.h"
41 #include <klfguiutil.h>
42 #include "klflibbrowser_p.h"
43 #include "klflibbrowser.h"
44 #include <ui_klflibbrowser.h>
45 #include "klfliblegacyengine.h"
46 
47 
49  : QWidget(
50 #if defined(Q_OS_WIN32)
51  0 /* parent */
52 #else
53  parent /* 0 */
54 #endif
55  , Qt::Window)
56 {
58 
59  u = new Ui::KLFLibBrowser;
60  u->setupUi(this);
61  u->tabResources->setContextMenuPolicy(Qt::CustomContextMenu);
62 
63  KLF_DEBUG_ASSIGN_REF_INSTANCE(u->searchBar, "libbrowser-searchbar") ;
64  u->searchBar->registerShortcuts(this);
65  // set found/not-found colors
66  u->searchBar->setColorFound(klfconfig.LibraryBrowser.colorFound);
67  u->searchBar->setColorNotFound(klfconfig.LibraryBrowser.colorNotFound);
68 
69  pResourceMenu = new QMenu(u->tabResources);
70  // connect actions
71  connect(u->aRename, SIGNAL(triggered()), this, SLOT(slotResourceRename()));
72  connect(u->aRenameSubRes, SIGNAL(triggered()), this, SLOT(slotResourceRenameSubResource()));
73  connect(u->aProperties, SIGNAL(triggered()), this, SLOT(slotResourceProperties()));
74  connect(u->aNewSubRes, SIGNAL(triggered()), this, SLOT(slotResourceNewSubRes()));
75  connect(u->aDelSubRes, SIGNAL(triggered()), this, SLOT(slotResourceDelSubRes()));
76  connect(u->aSaveTo, SIGNAL(triggered()), this, SLOT(slotResourceSaveTo()));
77  connect(u->aNew, SIGNAL(triggered()), this, SLOT(slotResourceNew()));
78  connect(u->aOpen, SIGNAL(triggered()), this, SLOT(slotResourceOpen()));
79  connect(u->aClose, SIGNAL(triggered()), this, SLOT(slotResourceClose()));
80  // and add them to menu
81  pResourceMenu->addAction((new KLFLibBrowserTabMenu(u->tabResources))->menuAction());
82  pResourceMenu->addSeparator();
83  pResourceMenu->addAction(u->aRename);
84  pResourceMenu->addAction(u->aRenameSubRes);
85  pResourceMenu->addAction(u->aProperties);
86  pResourceMenu->addSeparator();
87  pResourceMenu->addAction(u->aViewType);
88  pResourceMenu->addSeparator();
89  pResourceMenu->addAction(u->aNewSubRes);
90  pResourceMenu->addAction(u->aOpenSubRes);
91  pResourceMenu->addAction(u->aDelSubRes);
92  pResourceMenu->addSeparator();
93  pResourceMenu->addAction(u->aNew);
94  pResourceMenu->addAction(u->aOpen);
96  // pResourceMenu->addAction(u->aSaveTo);
97  pResourceMenu->addAction(u->aClose);
98 
100 
101  pTabCornerButton = new QPushButton(u->tabResources);
102  pTabCornerButton->setMenu(pResourceMenu);
103  u->tabResources->setCornerWidget(pTabCornerButton);
104 
105  connect(u->tabResources, SIGNAL(currentChanged(int)), this, SLOT(slotTabResourceShown(int)));
106  connect(u->tabResources, SIGNAL(customContextMenuRequested(const QPoint&)),
107  this, SLOT(slotShowTabContextMenu(const QPoint&)));
108 
109  // RESTORE
110 
111  QMenu * restoreMenu = new QMenu(this);
112  connect(u->aRestoreWithStyle, SIGNAL(triggered()), this, SLOT(slotRestoreWithStyle()));
113  connect(u->aRestoreLatexOnly, SIGNAL(triggered()), this, SLOT(slotRestoreLatexOnly()));
114  restoreMenu->addAction(u->aRestoreWithStyle);
115  restoreMenu->addAction(u->aRestoreLatexOnly);
116  u->btnRestore->setMenu(restoreMenu);
117 
118  connect(u->btnRestore, SIGNAL(clicked()), this, SLOT(slotRestoreWithStyle()));
119  connect(u->btnDelete, SIGNAL(clicked()), this, SLOT(slotDeleteSelected()));
120  connect(u->aDelete, SIGNAL(triggered()), u->btnDelete, SLOT(animateClick()));
121 
122  // IMPORT/EXPORT
123 
124  pImportExportMenu = new QMenu(this);
125  pImportExportMenu->addAction(u->aOpenAll);
126  pImportExportMenu->addAction(u->aExport);
127  pImportExportMenu->addAction(u->aExportSelection);
128  u->btnImportExport->setMenu(pImportExportMenu);
129 
130  connect(u->aOpenAll, SIGNAL(triggered()), this, SLOT(slotOpenAll()));
131  connect(u->aExport, SIGNAL(triggered()), this, SLOT(slotExport()));
132  connect(u->aExportSelection, SIGNAL(triggered()), this, SLOT(slotExportSelection()));
133 
134 
135  // CATEGORY/TAGS
136 
137  connect(u->wEntryEditor, SIGNAL(metaInfoChanged(const QMap<int,QVariant>&)),
138  this, SLOT(slotMetaInfoChanged(const QMap<int,QVariant>&)));
139 
140  connect(u->wEntryEditor, SIGNAL(restoreStyle(const KLFStyle&)),
141  this, SIGNAL(requestRestoreStyle(const KLFStyle&)));
142 
143  // OPEN / NEW BUTTONS IN WELCOME TAB
144 
145  connect(u->btnOpenRes, SIGNAL(clicked()), this, SLOT(slotResourceOpen()));
146  connect(u->btnCreateRes, SIGNAL(clicked()), this, SLOT(slotResourceNew()));
147 
148  // SHORTCUTS
149 
150  // cut/copy/paste
151  (void)new QShortcut(QKeySequence::Delete, this, SLOT(slotDeleteSelected()));
152  (void)new QShortcut(QKeySequence::Cut, this, SLOT(slotCut()));
153  (void)new QShortcut(QKeySequence::Copy, this, SLOT(slotCopy()));
154  (void)new QShortcut(QKeySequence::Paste, this, SLOT(slotPaste()));
155 
156  retranslateUi(false);
157 
158  // start with no entries selected
160 }
161 
162 void KLFLibBrowser::retranslateUi(bool alsoBaseUi)
163 {
164  if (alsoBaseUi)
165  u->retranslateUi(this);
166 
167  u->wEntryEditor->retranslateUi(alsoBaseUi);
168 
169  pResourceMenu->setTitle(tr("Resource Actions", "[[menu title]]"));
170  u->searchBar->setFocusOutText(" "+tr("Hit Ctrl-F, Ctrl-S or / to search within the current resource"));
171  pTabCornerButton->setText(tr("Resource"));
172 }
173 
174 
176 {
178 
179  int k;
180  for (k = 0; k < pLibViews.size(); ++k) {
181  KLFLibResourceEngine * engine = pLibViews[k]->resourceEngine();
182  delete pLibViews[k];
183  delete engine;
184  }
185 
186  delete u;
187 }
188 
189 
191 {
193 
194  if (obj->property("resourceTitleEditor").toBool() == true) {
195  if (ev->type() == QEvent::FocusOut) {
196  obj->deleteLater(); // if lost focus, cancel...
197  // don't eat event
198  }
199  if (ev->type() == QEvent::KeyPress) {
200  QKeyEvent *ke = (QKeyEvent*)ev;
201  if (ke->key() == Qt::Key_Escape) {
202  obj->deleteLater();
203  return true;
204  }
205  }
206  }
207 
208  if (ev->type() == QEvent::Hide &&
209  obj->property("klf_libbrowser_pdlg_want_hideautodelete").toBool() == true) {
210  // this object is a resource-operation progress dialog that was just hidden
211  klfDbg( ": progress dialog was hidden, deleting." ) ;
212  obj->deleteLater();
213  return true;
214  // return false; // continue with event handling
215  }
216 
217  return QWidget::eventFilter(obj, ev);
218 }
219 
221 {
223  if (viewc == NULL)
224  return -1;
225  return pLibViews.indexOf(viewc);
226 }
227 
229 {
230  int i = currentUrlIndex();
231  if (i < 0 || i >= pLibViews.size())
232  return QUrl();
233  return pLibViews[i]->url();
234 }
235 
236 
238 {
239  QList<QUrl> urls;
240  int k;
241  for (k = 0; k < pLibViews.size(); ++k) {
242  urls << pLibViews[k]->url();
243  }
244  return urls;
245 }
246 
248 {
250  if (viewc == NULL)
251  return NULL;
252  return viewc->resourceEngine();
253 }
254 
256 {
258  if (viewc == NULL)
259  return NULL;
260  return viewc->view();
261 }
262 
264 {
265  KLFLibBrowserViewContainer * viewc = findOpenResource(resource);
266  if (viewc == NULL)
267  return NULL;
268  return viewc->view();
269 }
270 
271 
272 
274 {
275  QVariantMap v;
276  // first save the list of open URLs
277  QList<QUrl> myurllist = openUrls();
278  QUrl currenturl = currentUrl();
279  QList<QVariant> urllist; // will hold URL's as QUrl's
280  QList<QVariant> viewstatelist; // will hold variantMap's
281  QList<QVariant> resroleflagslist; // will hold quint32's
282 
283  int k;
284  for (k = 0; k < myurllist.size(); ++k) {
285  KLFLibBrowserViewContainer *viewc = findOpenUrl(myurllist[k]);
286  if (viewc == NULL) {
287  qWarning()<<"Should NOT HAPPEN! viewc is NULL in KLFLibBrowser::saveGuiState()! URL-List=\n"
288  <<myurllist;
289  continue;
290  }
291  QVariantMap viewState = viewc->saveGuiState();
292  urllist << QVariant::fromValue<QUrl>(myurllist[k]);
293  viewstatelist << QVariant::fromValue<QVariantMap>(viewState);
294  resroleflagslist << QVariant::fromValue<quint32>(viewc->resourceRoleFlags());
295  }
296  v["UrlList"] = QVariant::fromValue<QVariantList>(urllist);
297  v["ViewStateList"] = QVariant::fromValue<QVariantList>(viewstatelist);
298  v["ResourceRoleFlagsList"] = QVariant::fromValue<QVariantList>(resroleflagslist);
299  v["CurrentUrl"] = QVariant::fromValue<QUrl>(currenturl);
300  v["WidgetSize"] = QVariant::fromValue<QSize>(size());
301  return v;
302 }
303 void KLFLibBrowser::loadGuiState(const QVariantMap& v, bool openURLs)
304 {
305  QUrl currenturl = v["CurrentUrl"].toUrl();
306  QList<QVariant> urllist = v["UrlList"].toList();
307  QList<QVariant> viewstatelist = v["ViewStateList"].toList();
308  QList<QVariant> resroleflagslist = v["ResourceRoleFlagsList"].toList();
309  QSize widgetsize = v["WidgetSize"].value<QSize>();
310  int k;
311  for (k = 0; k < urllist.size(); ++k) {
312  QUrl url = urllist[k].toUrl();
313  quint32 flags = resroleflagslist[k].value<quint32>();
314  klfDbg( "LibBrowser::loadGuiState: Opening url "<<url<<" with flags="<<flags ) ;
315  QVariantMap viewState = viewstatelist[k].toMap();
316  // don't open new URLs if openURLs is false
317  if ( !openURLs && findOpenUrl(url) == NULL )
318  continue;
319  // open this URL
320  bool res = openResourceFromGuiState(url, viewState);
321  // ignore flags, in case we eg. change library file, don't keep the old ones uncloseable
322  // updateResourceRoleFlags(..., flags);
323  if ( ! res ) {
324  qWarning()<<"KLFLibBrowser::loadGuiState: Can't open resource "<<url<<"! (flags="
325  <<flags<<")";
326  continue;
327  }
328  }
329  klfDbg( "Almost finished loading gui state." ) ;
330  KLFLibBrowserViewContainer *curviewc = findOpenUrl(currenturl);
331  if (curviewc != NULL)
332  u->tabResources->setCurrentWidget(curviewc);
333  klfDbg( "Loaded GUI state." ) ;
334 
335  if (widgetsize.width() > 0 && widgetsize.height() > 0)
336  resize(widgetsize);
337 }
338 
339 
340 
341 // static
343 {
345 
346  KLF_ASSERT_NOT_NULL( resource, "Resource is NULL!", return QString() ) ;
347 
348  QString basestr;
350  QString subresourcetitle = resource->defaultSubResource();
352  subresourcetitle
353  = resource->subResourceProperty(resource->defaultSubResource(),
355  basestr = QString("%1 - %2").arg(resource->title(), subresourcetitle);
356  } else {
357  basestr = resource->title();
358  }
360  basestr = "# "+basestr;
361  }
362  return basestr;
363 }
364 
365 
367 {
369 
370  klfDbg( "\turl is "<<url ) ;
371  int k;
372  for (k = 0; k < pLibViews.size(); ++k) {
373  klfDbg("\t\ttest lib view #"<<k) ;
374  klfDbg("\t\turl="<<pLibViews[k]->url() ) ;
375  // allow: * urls to be equal
376  // * this resource's URL to be less specific (shows more) than what we're searching for
377  uint fl = pLibViews[k]->view()->compareUrlTo(url, KlfUrlCompareEqual|KlfUrlCompareLessSpecific);
378  if (fl & KlfUrlCompareEqual ||
380  klfDbg( ": Found!" ) ;
381  return pLibViews[k];
382  }
383  }
384  return NULL;
385 }
386 
388 {
390 
391  int k;
392  for (k = 0; k < pLibViews.size(); ++k)
393  if (pLibViews[k]->resourceEngine() == resource)
394  return pLibViews[k];
395  return NULL;
396 }
397 
399 {
400  return qobject_cast<KLFLibBrowserViewContainer*>(u->tabResources->currentWidget());
401 }
403 {
405  if (v == NULL)
406  return NULL;
407  return v->view();
408 }
410 {
411  return qobject_cast<KLFLibBrowserViewContainer*>(u->tabResources->widget(tab));
412 }
414 {
415  klfDbg("Looking for flags "<<klfFmtCC("%#010x", testflags)<<" with mask "<<klfFmtCC("%#010x", mask)) ;
417  int k;
418  for (k = 0; k < pLibViews.size(); ++k) {
419  if ((pLibViews[k]->resourceRoleFlags() & mask) == testflags) {
420  klfDbg("Adding #"<<k<<": "<<pLibViews[k]<<", url="<<pLibViews[k]->url()) ;
421  list << pLibViews[k];
422  }
423  }
424  return list;
425 }
426 
427 
428 
429 bool KLFLibBrowser::openResource(const QString& url, uint resourceRoleFlags,
430  const QString& viewTypeIdentifier)
431 {
432  KLF_DEBUG_TIME_BLOCK(KLF_FUNC_NAME+QString("(QString,uint,QString)")) ;
433  return openResource(QUrl(url), resourceRoleFlags, viewTypeIdentifier);
434 }
435 
436 bool KLFLibBrowser::openResource(const QUrl& url, uint resourceRoleFlags,
437  const QString& viewTypeIdentifier)
438 {
439  KLF_DEBUG_TIME_BLOCK(KLF_FUNC_NAME+"(QUrl,uint,QString)") ;
440  klfDbg( " url="<<url.toString()<<"; resroleflags="<<resourceRoleFlags
441  <<"; vtypeidentifier="<<viewTypeIdentifier ) ;
442 
443  KLFLibBrowserViewContainer * openview = findOpenUrl(url);
444  if (openview != NULL) {
445  qDebug("KLFLibBrowser::openResource(%s,%u): This resource is already open.",
446  qPrintable(url.toString()), resourceRoleFlags);
447  if ((resourceRoleFlags & OpenNoRaise) == 0)
448  u->tabResources->setCurrentWidget(openview);
449  updateResourceRoleFlags(openview, resourceRoleFlags);
450  return true;
451  }
452 
454  if ( factory == NULL ) {
455  qWarning()<<KLF_FUNC_NAME<<": failed to find appropriate factory for url="<<url.toString()<<"!";
456  return false;
457  }
458  KLFLibResourceEngine * resource = factory->openResource(url, this);
459  if ( resource == NULL ) {
460  qWarning()<<KLF_FUNC_NAME<<": factory failed to open resource "<<url.toString()<<"!";
461  return false;
462  }
463 
464  // go on opening resource with our sister function
465  return openResource(resource, resourceRoleFlags, viewTypeIdentifier);
466 }
467 bool KLFLibBrowser::openResource(KLFLibResourceEngine *resource, uint resourceRoleFlags,
468  const QString& viewTypeIdentifier)
469 {
470  KLF_DEBUG_TIME_BLOCK(KLF_FUNC_NAME+"(KLFLibResourceEngine*,uint,QString)") ;
471  klfDbg( "\topening resource url="
473 
474  // KLFPleaseWaitPopup label(tr("Loading resource, please wait..."), this);
475 
476  KLF_ASSERT_NOT_NULL(resource,
477  "resource pointer is NULL! (flags="<<resourceRoleFlags<<",vti="<<viewTypeIdentifier<<")",
478  return false );
479 
480  KLFLibBrowserViewContainer * openview = findOpenResource(resource);
481  if (openview != NULL) {
482  qDebug("KLFLibBrowser::openResource(%p,%u): This resource is already open.",
483  resource, resourceRoleFlags);
484  if ((resourceRoleFlags & OpenNoRaise) == 0)
485  u->tabResources->setCurrentWidget(openview);
486  updateResourceRoleFlags(openview, resourceRoleFlags);
487  return true;
488  }
489 
490  resource->setParent(this);
491 
492  klfDbgT(": created resource. about to create view container.") ;
493 
494  // now create appropriate view for this resource
495  KLFLibBrowserViewContainer *viewc = new KLFLibBrowserViewContainer(resource, u->tabResources);
496 
497  klfDbgT(": adding tab page....") ;
498 
499  int i = u->tabResources->addTab(viewc, displayTitle(resource));
500  if ((resourceRoleFlags & OpenNoRaise) == 0)
501  u->tabResources->setCurrentWidget(viewc);
502  u->tabResources
503  ->refreshTabReadOnly(i, !resource->canModifyData(KLFLibResourceEngine::AllActionsData));
504  pLibViews.append(viewc);
505  setStyleSheet(styleSheet());
506  updateResourceRoleFlags(viewc, resourceRoleFlags);
507 
508 
509  // get informed about selection changes
510  connect(viewc, SIGNAL(entriesSelected(const KLFLibEntryList& )),
511  this, SLOT(slotEntriesSelected(const KLFLibEntryList& )));
512  // and of new category suggestions
513  connect(viewc, SIGNAL(moreCategorySuggestions(const QStringList&)),
514  this, SLOT(slotAddCategorySuggestions(const QStringList&)));
515 
516  connect(viewc, SIGNAL(requestRestore(const KLFLibEntry&, uint)),
517  this, SIGNAL(requestRestore(const KLFLibEntry&, uint)));
518  connect(viewc, SIGNAL(requestRestoreStyle(const KLFStyle&)),
519  this, SIGNAL(requestRestoreStyle(const KLFStyle&)));
520 
521  connect(viewc, SIGNAL(requestOpenUrl(const QString&)),
522  this, SLOT(openResource(const QString&)));
523 
524  connect(viewc, SIGNAL(resourceDataChanged(const QList<KLFLib::entryId>&)),
525  this, SLOT(slotResourceDataChanged(const QList<KLFLib::entryId>&)));
526  connect(resource, SIGNAL(resourcePropertyChanged(int)),
527  this, SLOT(slotResourcePropertyChanged(int)));
528  connect(resource, SIGNAL(subResourcePropertyChanged(const QString&, int)),
529  this, SLOT(slotSubResourcePropertyChanged(const QString&, int)));
530  connect(resource, SIGNAL(defaultSubResourceChanged(const QString&)),
531  this, SLOT(slotDefaultSubResourceChanged(const QString&)));
532 
533  // progress reporting originating from resource (eg. database operations)
534  connect(resource, SIGNAL(operationStartReportingProgress(KLFProgressReporter *, const QString&)),
535  this, SLOT(slotStartProgress(KLFProgressReporter *, const QString&)));
536  // progress reporting originating from view (eg. model updates)
537  connect(viewc, SIGNAL(viewOperationStartReportingProgress(KLFProgressReporter *, const QString&)),
538  this, SLOT(slotStartProgress(KLFProgressReporter *, const QString&)));
539 
540  // supply a context menu to view
541  connect(viewc, SIGNAL(viewContextMenuRequested(const QPoint&)),
542  this, SLOT(slotShowContextMenu(const QPoint&)));
543 
544 
545  // create a list of view types to attempt to open, in a given priority order
546  QStringList viewtypeident_try;
547  // * the argument to this function
548  viewtypeident_try << viewTypeIdentifier;
551  // * the sub-resource view type property (if applicable)
552  viewtypeident_try
553  << resource->subResourceProperty(resource->defaultSubResource(),
555  }
556  // * the resource view type property
557  viewtypeident_try << resource->viewType();
558  // * the suggested view type for this resource (as given by engine itself)
559  viewtypeident_try << resource->suggestedViewTypeIdentifier();
560  // * the default view type suggested by the factory
561  viewtypeident_try << KLFLibViewFactory::defaultViewTypeIdentifier();
562  // * a "default" view type (last resort, hoping it exists!)
563  viewtypeident_try << QLatin1String("default");
564 
565  klfDbgT(": created resource. about to test view types.") ;
566  klfDbg( "\tView types: "<<viewtypeident_try ) ;
567 
568  int k;
569  // try each view type, first success is kept.
570  for (k = 0; k < viewtypeident_try.size(); ++k) {
571  if (viewtypeident_try[k].isEmpty())
572  continue;
573 
574  KLFLibViewFactory *viewfactory =
575  KLFLibViewFactory::findFactoryFor(viewtypeident_try[k]);
576  if (viewfactory == NULL) {
577  klfDbg( "can't find view factory for view type identifier "
578  <<viewtypeident_try[k]<<"!" ) ;
579  continue;
580  }
581  if ( ! viewfactory->canCreateLibView(viewtypeident_try[k], resource) ) {
582  klfDbg( "incompatible view type identifier "<<viewtypeident_try[k]
583  <<"for resource "<<resource->url()<<"." ) ;
584  continue;
585  }
586  bool r = viewc->openView(viewtypeident_try[k]);
587  if (!r) {
588  klfDbg( "can't create view! viewtypeident="<<viewtypeident_try[k]<<"." ) ;
589  continue;
590  }
591 
592  klfDbgT(": found and instantiated good view type="<<viewtypeident_try[k]) ;
593 
594  // found good view type !
595  resource->setViewType(viewtypeident_try[k]);
596  // quit for() on first success.
597  break;
598  }
599 
600  klfDbgT(": requiring cat suggestions.") ;
601 
602  // get more category completions
603  viewc->view()->wantMoreCategorySuggestions();
604 
605  // hide welcome page if it's shown
606  if ((i = u->tabResources->indexOf(u->tabWelcome)) != -1)
607  u->tabResources->removeTab(i);
608 
609  klfDbgT(": end of function") ;
610 
611  return true;
612 }
613 
614 bool KLFLibBrowser::openResourceFromGuiState(const QUrl& url, const QVariantMap& guiState)
615 {
617  // peek into GUI state to open the correct view
618  QString vti = guiState.value(QLatin1String("CurrentViewTypeIdentifier")).toString();
619  klfDbg("view-type-identifier is "<<vti<<"; guiState is "<<guiState) ;
620  bool result = openResource(url, NoChangeFlag, vti);
621  if (!result)
622  return false;
623  klfDbg("restoring gui state..") ;
625  KLF_ASSERT_NOT_NULL( viewc, "can't find the view container we just opened!", return false ) ;
626  viewc->loadGuiState(guiState);
627  return true;
628 }
629 
630 
632 {
634 
636  if (w == NULL)
637  return false;
638 
639  return slotResourceClose(w);
640 }
641 
642 
643 void KLFLibBrowser::updateResourceRoleFlags(KLFLibBrowserViewContainer *viewc, uint resroleflags)
644 {
645  KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
646 
647  KLF_ASSERT_NOT_NULL(viewc, "the viewc parameter is null!", return; ) ;
648 
649  if (resroleflags & NoChangeFlag)
650  return;
651 
652  // only store flags that don't act 'now'
653  resroleflags = resroleflags & ~NowMask;
654 
655  klfDbg("updating flags for resource="<<viewc->url()<<"; flags after mask="
656  <<klfFmtCC("%#010x", resroleflags)) ;
657 
658  // If history resroleflags is set, then unset that flag to its previous owner (history role flag
659  // is exclusive).
660  // Same respectively for archive flag.
661  uint exclusive_flag_list[] = { HistoryRoleFlag, ArchiveRoleFlag, 0 } ;
662  int j;
663  for (j = 0; exclusive_flag_list[j] != 0; ++j) {
664  uint xflag = exclusive_flag_list[j];
665  if (resroleflags & xflag) {
666  // If we are about to set this flag to resource 'viewc', then make sure no one (else) has it
667  int k;
668  for (k = 0; k < pLibViews.size(); ++k) {
669  if (pLibViews[k] == viewc)
670  continue; // skip our targeted view
671  uint fl = pLibViews[k]->resourceRoleFlags();
672  if (fl & xflag) {
673  // unset it
674  pLibViews[k]->setResourceRoleFlags(fl & ~xflag);
675  }
676  }
677  }
678  }
679 
680  // now we can set the appropriate flags on the requested resource view
681  viewc->setResourceRoleFlags(resroleflags);
682 }
683 
684 
686 {
688  klfDbg( "\t tabIndex="<<tabIndex ) ;
689 
691  qobject_cast<KLFLibBrowserViewContainer*>(u->tabResources->widget(tabIndex));
692  if (viewc == NULL || tabIndex < 0) {
693  emit resourceTabChanged(QUrl());
694  return;
695  }
696 
697  // redirect searches to the correct view
698  u->searchBar->setSearchTarget(viewc);
699 
700  klfDbg("setting up view type menu...") ;
701 
702  // set up view type menu appropriately
704  QMenu *viewTypeMenu = u->aViewType->menu();
705  if (viewTypeMenu == NULL) {
706  viewTypeMenu = new QMenu(this);
707  u->aViewType->setMenu(viewTypeMenu);
708  KLF_DEBUG_WATCH_OBJECT(viewTypeMenu) ;
709  }
710  viewTypeMenu->clear();
711  int k;
712  for (k = 0; k < actions.size(); ++k) {
713  viewTypeMenu->addAction(actions[k]);
714  }
715 
716  QMenu * openSubResMenu = u->aOpenSubRes->menu();
717  if (openSubResMenu == NULL) {
718  openSubResMenu = new QMenu(this);
719  u->aOpenSubRes->setMenu(openSubResMenu);
720  KLF_DEBUG_WATCH_OBJECT(openSubResMenu) ;
721  }
722  openSubResMenu->clear();
723  QList<QAction*> openSubResActions = viewc->openSubResourceActions();
724  for (k = 0; k < openSubResActions.size(); ++k) {
725  openSubResMenu->addAction(openSubResActions[k]);
726  }
727  if (openSubResActions.size() > 0)
728  u->aOpenSubRes->setEnabled(true);
729  else
730  u->aOpenSubRes->setEnabled(false);
731 
732  // refresh selection-related displays
733  KLFAbstractLibView *view = viewc->view();
734  if (view != NULL)
737 
738  emit resourceTabChanged(viewc->url());
739 }
740 
742 {
744 
745  int tab = u->tabResources->getTabAtPoint(pos);
746  if (tab != -1) {
747  u->tabResources->setCurrentIndex(tab);
748  }
749  pResourceMenu->popup(u->tabResources->mapToGlobal(pos));
750 }
751 
753 {
754  slotResourceRename(false);
755 }
757 {
758  slotResourceRename(true);
759 }
760 void KLFLibBrowser::slotResourceRename(bool renamingSubResource)
761 {
763  klfDbg("renamingSubResource="<<renamingSubResource) ;
764 
765  int tab = u->tabResources->currentIndex();
767  if (tab < 0 || viewc == NULL)
768  return;
769 
770  klfDbg( ": Rename! renamingSubResource="<<renamingSubResource ) ;
771 
772  KLFLibResourceEngine *res = viewc->resourceEngine();
773 
774  if ( ! renamingSubResource && ! res->canModifyProp(KLFLibResourceEngine::PropTitle) )
775  return;
776 
777  if ( renamingSubResource &&
782  ) )
783  return;
784 
785  QLineEdit * editor = new QLineEdit(u->tabResources);
786  editor->setGeometry(u->tabResources->getTabRect(tab));
787  editor->show();
788  if (!renamingSubResource)
789  editor->setText(res->title());
790  else
791  editor->setText(res->subResourceProperty(res->defaultSubResource(),
793  editor->setFocus();
794  editor->setProperty("tabURL", viewc->url());
795  editor->setProperty("resourceTitleEditor", true);
796  editor->setProperty("needsBackground", true);
797  editor->setProperty("renamingSubResource", renamingSubResource);
798  editor->setStyleSheet("");
799  editor->installEventFilter(this);
800 
801  // kill editor if tab changes
802  connect(u->tabResources, SIGNAL(currentChanged(int)), editor, SLOT(deleteLater()));
803  connect(editor, SIGNAL(returnPressed()), this, SLOT(slotResourceRenameFinished()));
804 }
805 
807 {
809 
810  QObject * editor = sender();
811  if (editor == NULL) {
812  qWarning("KLFLibBrowser::slotResourceRenameFinished: no sender!");
813  return;
814  }
815  bool isRenamingSubResource = editor->property("renamingSubResource").toBool();
816  QUrl url = editor->property("tabURL").toUrl();
818  if (viewc == NULL) {
819  qWarning()<<KLF_FUNC_NAME<<": can't find the resource with URL "<<url;
820  return;
821  }
822  KLFLibResourceEngine *res = viewc->resourceEngine();
823  QString text = editor->property("text").toString();
824  if (!isRenamingSubResource)
825  res->setTitle(text);
826  else
828  QVariant::fromValue<QString>(text));
829 
830  editor->deleteLater();
831 }
832 
834 {
836 
837  if (view == NULL)
838  view = curView();
839  if (view == NULL)
840  return false;
841 
842  if (!force && view->resourceRoleFlags() & NoCloseRoleFlag) // sorry, can't close.
843  return false;
844 
845  klfDbg( "Close! resflags="<<view->resourceRoleFlags() ) ;
846 
847  int tabindex = u->tabResources->indexOf(view);
848  if (tabindex < 0) {
849  qWarning("KLFLibBrowser::closeResource(url): can't find view in tab widget?!?\n"
850  "\turl=%s, viewwidget=%p", qPrintable(view->url().toString()), view);
851  return false;
852  }
853 
854  if (!force && klfconfig.LibraryBrowser.confirmClose) {
855  // ask user for confirmation
856  QMessageBox::StandardButton btn =
857  QMessageBox::question(this, tr("Close Resource"), tr("Do you want to close this resource?"),
858  QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Yes);
859  if (btn != QMessageBox::Yes)
860  return false;
861  }
862 
863  u->tabResources->removeTab(tabindex);
864  int index = pLibViews.indexOf(view);
865  pLibViews.removeAt(index);
866  // delete view and engine
867  KLFLibResourceEngine *resource = view->resourceEngine();
868  delete view;
869  delete resource;
870 
871  if (u->tabResources->count() == 0)
872  u->tabResources->addTab(u->tabWelcome, QIcon(":/pics/library.png"), tr("Library Browser"));
873 
874  return true;
875 }
876 
878 {
880 
882  if (view == NULL) {
883  qWarning("KLFLibBrowser::slotResourceProperties: NULL View!");
884  return;
885  }
886  KLFLibResPropEditorDlg * dialog = new KLFLibResPropEditorDlg(view->resourceEngine(), this);
887  dialog->show();
888 }
889 
891 {
893 
895  if (view == NULL) {
896  qWarning("KLFLibBrowser::slotResourceProperties: NULL View!");
897  return false;
898  }
899  KLFLibResourceEngine *res = view->view()->resourceEngine();
901  if (name.isEmpty())
902  return false;
903 
904  // see remark in comment below
905  QUrl url = res->url();
906  url.removeAllQueryItems("klfDefaultSubResource");
907  url.addQueryItem("klfDefaultSubResource", name);
908 
909  klfDbg( "KLFLibBrowser::slotRes.New.S.Res(): Create sub-resource named "<<name<<", opening "<<url ) ;
910 
911  // in case of a view displaying all sub-resources, this also works because findOpenUrl() will find
912  // that view and raise it.
913  return openResource(url);
914 }
915 
917 {
919 
921  KLF_ASSERT_NOT_NULL(viewc , "NULL View Container!" , return false; ) ;
922  KLFAbstractLibView *view = viewc->view();
923  KLF_ASSERT_NOT_NULL(view , "NULL View in container "<<viewc<<" !" , return false; ) ;
924  KLFLibResourceEngine *res = view->resourceEngine();
925  KLF_ASSERT_NOT_NULL(res , "NULL resource for view="<<view<<" !" , return false; ) ;
926 
927  KLF_ASSERT_CONDITION( res->supportedFeatureFlags() & KLFLibResourceEngine::FeatureSubResources ,
928  "Sub-resources are not supported in resource "<<res->url()<<"!"
929  " Cannot delete sub-resource!",
930  return false; ) ;
931 
932  if (res->subResourceList().size() <= 1) {
933  QMessageBox::warning(this, tr("Error"),
934  tr("You may not delete the last remaining sub-resource of this resource."));
935  klfDbg("Attempted to delete last remaining sub-resource"<<res->defaultSubResource()<<" of resource "
936  <<res->url()<<". Not allowed.") ;
937  return false;
938  }
939 
940  QString curSubResource = res->defaultSubResource();
941  QString curSubResTitle = curSubResource;
942  if (res->supportedFeatureFlags() & KLFLibResourceEngine::FeatureSubResourceProps) {
943  QString t = res->subResourceProperty(curSubResource, KLFLibResourceEngine::SubResPropTitle).toString();
944  if (!t.isEmpty())
945  curSubResTitle = t;
946  }
947 
948  // remove the current sub-resource: first ask user confirmation
949 
950  QMessageBox::StandardButton btn =
951  QMessageBox::question(this, tr("Delete Sub-Resource", "[[msgbox title]]"),
952  tr("Do you really want to delete the sub-resource <b>%1</b>, "
953  "with all its contents, from resource <b>%2</b>?")
954  .arg(curSubResTitle, displayTitle(res)),
955  QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Cancel);
956  if (btn != QMessageBox::Yes)
957  return false;
958 
959  // now remove that sub-resource
960  bool result = res->deleteSubResource(curSubResource);
961 
962  if (!result) {
963  // report failure
964  QMessageBox::critical(this, tr("Delete Sub-Resource", "[[msgbox title]]"),
965  tr("Deleting sub-resource failed."));
966  return false;
967  }
968 
969  // close the corresponding tab.
970  slotResourceClose(viewc, true);
971  return true;
972 }
973 
975 {
977 
979  if (url.isEmpty())
980  return false;
981  bool r = openResource(url);
982  if ( ! r ) {
983  QMessageBox::critical(this, tr("Error"), tr("Failed to open library resource `%1'!")
984  .arg(url.toString()));
985  }
986  return r;
987 }
988 
990 {
992 
994  if (resource == NULL)
995  return false;
996 
997  return openResource(resource);
998 }
999 
1001 {
1002  return false;
1003  // YET TO BE IMPLEMENTED... using the factories to get a save to... widget..
1004  // KLFLibBrowserViewContainer *view = curView();
1005  // if (view == NULL) {
1006  // qWarning("KLFLibBrowser::slotResourceProperties: NULL View!");
1007  // return false;
1008  // }
1009 }
1010 
1012 {
1014 
1015  // KLFLibResourceEngine *resource = qobject_cast<KLFLibResourceEngine*>(sender());
1016  // if (resource == NULL) {
1017  // qWarning("KLFLibBrowser::slotResourceDataChanged: NULL sender or not resource!");
1018  // return;
1019  // }
1020  KLFLibBrowserViewContainer *viewc = qobject_cast<KLFLibBrowserViewContainer*>(sender());
1021  if (viewc == NULL) {
1022  qWarning()<<"KLFLibBrowser::slotResourceDataChanged: NULL sender or not KLFLibBro.ViewCont.!";
1023  return;
1024  }
1026 
1027  KLFAbstractLibView * view = viewc->view();
1028  if (view == NULL) {
1029  qWarning()<<"KLFLibBrowser::slotResourceDataChanged: NULL view !!";
1030  return;
1031  }
1033 }
1035 {
1037 
1038  KLFLibResourceEngine *resource = qobject_cast<KLFLibResourceEngine*>(sender());
1039  if (resource == NULL) {
1040  qWarning("KLFLibBrowser::slotResourcePropertyChanged: NULL sender or not resource!");
1041  return;
1042  }
1043  slotUpdateForResourceProperty(resource, propId);
1044 }
1045 
1047 {
1049  klfDbg("res="<<resource<<", propId="<<propId) ;
1050 
1052 
1053  KLFLibBrowserViewContainer *view = findOpenResource(resource);
1054  if (view == NULL) {
1055  qWarning()<<"KLFLibBrowser::slotResourcePropertyChanged: can't find view for resource "
1056  <<resource<<", url="<<resource->url()<<"!";
1057  return;
1058  }
1060  // the title is also affected by the locked state (# in front
1061  u->tabResources->setTabText(u->tabResources->indexOf(view), displayTitle(resource));
1062  }
1063  if (propId == KLFLibResourceEngine::PropLocked) {
1064  u->tabResources->refreshTabReadOnly(u->tabResources->indexOf(view),
1066  u->wEntryEditor
1067  ->setInputEnabled(resource->canModifyData(KLFLibResourceEngine::ChangeData));
1068  u->wEntryEditor->displayEntries(view->view()->selectedEntries());
1069  }
1070 }
1071 
1072 void KLFLibBrowser::slotSubResourcePropertyChanged(const QString& subResource, int propId)
1073 {
1075  Q_UNUSED(subResource) ;
1076  klfDbg("subResource="<<subResource<<", propId="<<propId) ;
1077 
1078  KLFLibResourceEngine *resource = qobject_cast<KLFLibResourceEngine*>(sender());
1079  if (resource == NULL) {
1080  qWarning("KLFLibBrowser::slotSubResourcePropertyChanged: NULL sender or not resource!");
1081  return;
1082  }
1083 
1086  if (propId < 0 || propId == KLFLibResourceEngine::SubResPropTitle) {
1087  // fake a resource property title change (updated stuff is the same)
1089  }
1090  if (propId < 0 || propId == KLFLibResourceEngine::SubResPropLocked) {
1091  // fake a resource property locked state change (updated stuff is the same)
1093  }
1094 }
1095 
1097 {
1099  Q_UNUSED(subResource) ;
1100  klfDbg("subResource="<<subResource) ;
1101 
1102  KLFLibResourceEngine *resource = qobject_cast<KLFLibResourceEngine*>(sender());
1103  if (resource == NULL) {
1104  qWarning("KLFLibBrowser::slotDefaultSubResourceChanged: NULL sender or not resource!");
1105  return;
1106  }
1107  // view already does a full refresh. We will just refresh the tab title.
1108  // fake a resource property title/locked state change (updated stuff is the same)
1111 }
1112 
1113 
1115 {
1117 
1118  KLFAbstractLibView * view = curLibView();
1119  if ( view == NULL )
1120  return;
1121  view->restoreWithStyle();
1122 }
1123 
1125 {
1127 
1128  KLFAbstractLibView * view = curLibView();
1129  if ( view == NULL )
1130  return;
1131  view->restoreLatexOnly();
1132 }
1133 
1135 {
1137 
1138  KLFAbstractLibView * view = curLibView();
1139  if ( view == NULL )
1140  return;
1141  KLFLibResourceEngine * resource = view->resourceEngine();
1143  return;
1144 
1146  klfDbg("selected "<<sel.size()<<" items:" <<sel);
1147 
1148  if (sel.isEmpty())
1149  return;
1150 
1151  QMessageBox::StandardButton res
1152  = QMessageBox::question(this, tr("Delete?"),
1153  tr("Delete %n selected item(s) from resource \"%1\"?", "", sel.size())
1154  .arg(resource->title()),
1155  QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Cancel);
1156  if (res != QMessageBox::Yes)
1157  return; // abort action
1158 
1159  resource->deleteEntries(sel);
1160 }
1161 
1163 {
1165 
1166  bool master = false;
1167  bool canrename = false;
1168  bool canrenamesubres = false;
1169  bool cansaveto = false;
1170  bool cannewsubres = false;
1171  bool candelsubres = false;
1172  uint resrolefl = 0;
1173  uint resfeatureflags = 0;
1174 
1176  if ( view != NULL ) {
1177  master = true;
1178  KLFLibResourceEngine *res = view->resourceEngine();
1180  resfeatureflags = res->supportedFeatureFlags();
1181  cansaveto = (resfeatureflags & KLFLibResourceEngine::FeatureSaveTo);
1182  resrolefl = view->resourceRoleFlags();
1183  cannewsubres = (resfeatureflags & KLFLibResourceEngine::FeatureSubResources) &&
1184  (res->canCreateSubResource());
1185  candelsubres = (resfeatureflags & KLFLibResourceEngine::FeatureSubResources) &&
1187  canrenamesubres = (resfeatureflags & KLFLibResourceEngine::FeatureSubResources) &&
1188  (resfeatureflags & KLFLibResourceEngine::FeatureSubResourceProps) &&
1191  }
1192 
1193  u->aRename->setEnabled(canrename);
1194  u->aRenameSubRes->setEnabled(canrenamesubres);
1195  u->aProperties->setEnabled(master);
1196  u->aNewSubRes->setEnabled(master && cannewsubres);
1197  u->aDelSubRes->setEnabled(master && candelsubres);
1198  u->aSaveTo->setEnabled(master && cansaveto);
1199  u->aNew->setEnabled(true);
1200  u->aOpen->setEnabled(true);
1201  u->aClose->setEnabled(master && !(resrolefl & NoCloseRoleFlag));
1202 }
1203 
1204 
1205 
1207 {
1209  klfDbg( "(): "<<entries ) ;
1210  if (entries.size()>=1)
1211  klfDbg( "Tag of first selected entry="<<entries[0].property(KLFLibEntry::Tags) ) ;
1212 
1213  KLFAbstractLibView *view = curLibView();
1214  if (view != NULL) {
1215  u->wEntryEditor
1216  ->setInputEnabled(view->resourceEngine()->canModifyData(KLFLibResourceEngine::ChangeData));
1217  }
1218 
1219  u->wEntryEditor->displayEntries(entries);
1220 
1221  u->btnDelete->setEnabled(entries.size() > 0);
1222  u->aDelete->setEnabled(u->btnDelete->isEnabled());
1223  u->btnRestore->setEnabled(entries.size() == 1);
1224 
1225  emit libEntriesSelected(entries);
1226 }
1227 
1229 {
1230  klfDbg( "KLFLibBrowser: got category suggestions: "<<catlist ) ;
1231  u->wEntryEditor->addCategorySuggestions(catlist);
1232 }
1233 
1235 {
1237 
1238  KLFAbstractLibView * view = curLibView();
1239  if ( view == NULL )
1240  return;
1241 
1242  QMenu *menu = new QMenu(view);
1243 
1244  QAction *a1 = menu->addAction(QIcon(":/pics/restoreall.png"), tr("Restore latex formula and style"),
1245  view, SLOT(restoreWithStyle()));
1246  QAction *a2 = menu->addAction(QIcon(":/pics/restore.png"), tr("Restore latex formula only"),
1247  view, SLOT(restoreLatexOnly()));
1248  menu->addSeparator();
1249  // NOTE: the QKeySequences given here are only for display in the context menu. Their functionality
1250  // is due to additional QShortcuts declared in the constructor. (!) (reason: these actions are
1251  // short-lived, and having global actions would require keeping their enabled status up-to-date
1252  // + we want to add view-given context menu actions dynamically)
1253  QAction *acut = menu->addAction(QIcon(":/pics/cut.png"), tr("Cut"), this, SLOT(slotCut()),
1254  QKeySequence::Cut);
1255  QAction *acopy = menu->addAction(QIcon(":/pics/copy.png"), tr("Copy"), this, SLOT(slotCopy()),
1256  QKeySequence::Copy);
1257  QAction *apaste = menu->addAction(QIcon(":/pics/paste.png"), tr("Paste"), this, SLOT(slotPaste()),
1258  QKeySequence::Paste);
1259  menu->addSeparator();
1260  QAction *adel = menu->addAction(QIcon(":/pics/delete.png"), tr("Delete from library"),
1261  this, SLOT(slotDeleteSelected()), QKeySequence::Delete);
1262  menu->addSeparator();
1263 
1264  QMenu *copytomenu = new QMenu(menu);
1265  QMenu *movetomenu = new QMenu(menu);
1266  int k;
1267  QAction *acopythere, *amovethere;
1268  int n_destinations = 0;
1269  for (k = 0; k < pLibViews.size(); ++k) {
1270  if (pLibViews[k]->url() == view->url()) // skip this view
1271  continue;
1272  KLFLibResourceEngine *res = pLibViews[k]->resourceEngine();
1273  QUrl viewurl = pLibViews[k]->url();
1274  n_destinations++;
1275  acopythere = copytomenu->addAction(displayTitle(res), this, SLOT(slotCopyToResource()));
1276  acopythere->setProperty("resourceViewUrl", viewurl);
1277  amovethere = movetomenu->addAction(displayTitle(res), this, SLOT(slotMoveToResource()));
1278  amovethere->setProperty("resourceViewUrl", viewurl);
1280  acopythere->setEnabled(false);
1281  amovethere->setEnabled(false);
1282  }
1283  }
1284  QAction *acopyto = menu->addMenu(copytomenu);
1285  acopyto->setText(tr("Copy to"));
1286  acopyto->setIcon(QIcon(":/pics/copy.png"));
1287  QAction *amoveto = menu->addMenu(movetomenu);
1288  amoveto->setText(tr("Move to"));
1289  amoveto->setIcon(QIcon(":/pics/move.png"));
1290 
1291  menu->addSeparator();
1292  menu->addMenu(pResourceMenu);
1293 
1294  // Needed for when user pops up a menu without selection (ie. short list, free white space under)
1295  KLFLibEntryList selected = view->selectedEntries();
1296  bool cancopy = (selected.size() > 0) && n_destinations;
1297  bool canre = (selected.size() == 1);
1300  a1->setEnabled(canre);
1301  a2->setEnabled(canre);
1302  adel->setEnabled(candel && selected.size());
1303  acut->setEnabled(cancopy && candel);
1304  acopy->setEnabled(cancopy);
1305  apaste->setEnabled(canpaste);
1306  acopyto->setEnabled(cancopy);
1307  amoveto->setEnabled(cancopy && candel);
1308 
1309  // add view's own actions
1310 
1311  QList<QAction*> viewActions = view->addContextMenuActions(pos);
1312  if (viewActions.size())
1313  menu->addSeparator(); // separate view's menu items from ours
1314  for (k = 0; k < viewActions.size(); ++k) {
1315  klfDbg( "Added action "<<k<<": "<<viewActions[k] ) ;
1316  menu->addAction(viewActions[k]);
1317  }
1318 
1319  menu->popup(view->mapToGlobal(pos));
1320 }
1321 
1322 
1323 
1325 {
1327 
1328  QWidget *w = u->tabResources->currentWidget();
1329  KLFLibBrowserViewContainer *wviewc = qobject_cast<KLFLibBrowserViewContainer*>(w);
1330  if (wviewc == NULL) {
1331  qWarning("Current view is not a KLFLibBrowserViewContainer or no current tab widget!");
1332  return;
1333  }
1334  if (props.isEmpty()) {
1335  klfDbg("no changes!");
1336  return;
1337  }
1338  KLFAbstractLibView * wview = wviewc->view();
1339  if ( wview == NULL )
1340  return;
1341  QList<KLFLib::entryId> selected = wview->selectedEntryIds();
1342  KLFLibResourceEngine *resource = wview->resourceEngine();
1343  QList<int> keys = props.keys();
1344  QList<QVariant> values;
1345  int k;
1346  for (k = 0; k < keys.size(); ++k)
1347  values << props[keys[k]];
1348  bool r = resource->changeEntries(selected, keys, values);
1349  if ( ! r ) {
1350  QMessageBox::warning(this, tr("Error"),
1351  tr("Failed to write meta-information!"));
1352  // and refresh display
1354  return;
1355  }
1356 
1357  // ensure that exactly the modified items are selected, as view's refresh mechanism does
1358  // not garantee to preserve selection
1359  wview->selectEntries(selected);
1360 
1361  // if we categorized/tagged a formula in the history resource, copy it to the archive if the relevant
1362  // setting is enabled
1366  klfDbg("vHistory="<<vHistory<<", vArchive="<<vArchive<<", wviewc="<<wviewc) ;
1367  if (vHistory != NULL && vArchive != NULL && vHistory != vArchive &&
1368  vHistory == wviewc) {
1369  klfDbg("categorized formula in history. copying it to archive");
1370  // copy the formula from history to archive
1371  KLFLibEntryList entryList = wview->selectedEntries();
1372  if (entryList.isEmpty()) {
1373  qWarning()<<KLF_FUNC_NAME<<": no selected entries ?!?";
1374  } else {
1375  KLFAbstractLibView *archiveView = vArchive->view();
1376  KLFLibResourceEngine *archiveRes = vArchive->resourceEngine();
1377  if (archiveRes == NULL || archiveView == NULL) {
1378  qWarning()<<KLF_FUNC_NAME<<": archiveRes or archiveView is NULL ?!?";
1379  } else {
1380  QList<KLFLib::entryId> insertedIds = archiveRes->insertEntries(entryList);
1381  if (!insertedIds.size() || insertedIds.contains(-1)) {
1382  QMessageBox::critical(this, tr("Error"), tr("Error copying the given items to the archive!"));
1383  } else {
1384  u->tabResources->setCurrentWidget(vArchive);
1385  // and select those items in archive that were inserted.
1386  archiveView->selectEntries(insertedIds);
1387  }
1388  }
1389  }
1390  }
1391  }
1392 }
1393 
1395 {
1396  slotCopyMoveToResource(sender(), false);
1397 }
1398 
1400 {
1401  slotCopyMoveToResource(sender(), true);
1402 }
1403 
1405 {
1407 
1408  QUrl destUrl = action->property("resourceViewUrl").toUrl();
1409  if (destUrl.isEmpty()) {
1410  qWarning()<<"KLFLibBrowser::slotCopyMoveToResource(): bad sender property ! sender is a `"
1411  <<action->metaObject()->className()<<"'; expected QAction with 'resourceViewUrl' property set.";
1412  return;
1413  }
1414  KLFAbstractLibView *sourceView = curLibView();
1415  if (sourceView == NULL) {
1416  qWarning()<<"KLFLibBrowser::slotCopyMoveToResource(): source view is NULL!";
1417  return;
1418  }
1419  KLFLibBrowserViewContainer *destViewC = findOpenUrl(destUrl);
1420  if (destViewC == NULL || destViewC->view() == NULL) {
1421  qWarning()<<"KLFLibBrowser::slotCopyMoveToResource(): can't find dest view url for URL="<<destUrl<<" !";
1422  return;
1423  }
1424  KLFAbstractLibView *destView = destViewC->view();
1425  // now do the copy/move:
1426  slotCopyMoveToResource(destView, sourceView, move);
1427 }
1428 
1430  bool move)
1431 {
1433 
1434  QList<KLFLib::entryId> selectedids = source->selectedEntryIds();
1435  KLFLibEntryList items = source->selectedEntries();
1436 
1437  QList<int> inserted = dest->resourceEngine()->insertEntries(items);
1438  if ( inserted.isEmpty() || inserted.contains(-1) ) {
1439  QString msg = move ? tr("Failed to move the selected items.")
1440  : tr("Failed to copy the selected items.");
1441  QMessageBox::critical(this, tr("Error"), msg, QMessageBox::Ok, QMessageBox::Ok);
1442  return;
1443  }
1444  if (move)
1445  source->resourceEngine()->deleteEntries(selectedids);
1446 }
1447 
1449 {
1451 
1452  KLFAbstractLibView * view = curLibView();
1453  if ( view == NULL )
1454  return;
1455  if ( view->selectedEntries().size() == 0 ||
1457  return;
1458 
1459  QList<KLFLib::entryId> selected = view->selectedEntryIds();
1460  slotCopy();
1461  view->resourceEngine()->deleteEntries(selected);
1462 }
1464 {
1466 
1467  KLFAbstractLibView * view = curLibView();
1468  if ( view == NULL )
1469  return;
1470  if ( view->selectedEntries().size() == 0 )
1471  return;
1472 
1473  KLFLibEntryList elist = view->selectedEntries();
1474  QVariantMap vprops;
1475  vprops["Url"] = view->url(); // originating URL
1476 
1477  QMimeData *mimeData = KLFAbstractLibEntryMimeEncoder::createMimeData(elist, vprops);
1478  QApplication::clipboard()->setMimeData(mimeData);
1479 }
1481 {
1483 
1484  KLFAbstractLibView * view = curLibView();
1485  if ( view == NULL )
1486  return;
1487 
1488  KLFLibEntryList elist;
1489  QVariantMap vprops;
1490 
1491  const QMimeData* mimeData = QApplication::clipboard()->mimeData();
1492  bool result =
1493  KLFAbstractLibEntryMimeEncoder::decodeMimeData(mimeData, &elist, &vprops);
1494  if (!result) {
1495  QMessageBox::critical(this, tr("Error"), tr("The clipboard doesn't contain any appropriate data."));
1496  return;
1497  }
1498 
1499  klfDbg( ": Pasting data! props="<<vprops ) ;
1500  QList<KLFLib::entryId> inserted = view->resourceEngine()->insertEntries(elist);
1501  if (inserted.isEmpty() || inserted.contains(-1)) {
1502  QMessageBox::critical(this, tr("Error"), tr("Error pasting items"));
1503  }
1504 }
1505 
1506 
1508 {
1510 
1511  QStringList exportFilterList;
1512  QStringList filterlist;
1513  QString exportFilter;
1515  int k;
1516  for (k = 0; k < locfiletypes.size(); ++k) {
1517  exportFilterList << locfiletypes[k].filter;
1518  filterlist << locfiletypes[k].filepattern;
1519  }
1520  exportFilterList.prepend(tr("All Known Library Files (%1)").arg(filterlist.join(" ")));
1521  exportFilterList << tr("All Files (*)");
1522  exportFilter = exportFilterList.join(";;");
1523  QString selectedFilter;
1525  QString fn = QFileDialog::getOpenFileName(this, tr("Open Library File"), dir, exportFilter, &selectedFilter);
1526  if (fn.isEmpty())
1527  return;
1528 
1530 
1531  int ifilter = exportFilterList.indexOf(selectedFilter);
1532  ifilter--; // index in locfiletypes now
1533  QString selectedScheme;
1534  if (ifilter >= 0 && ifilter < locfiletypes.size()) {
1535  selectedScheme = locfiletypes[ifilter].scheme;
1536  } else {
1538  }
1539  if (!QFileInfo(fn).isReadable()) {
1540  qWarning()<<KLF_FUNC_NAME<<": The given file name is not readable: "<<fn;
1541  QMessageBox::critical(this, tr("Error"), tr("The given file cannot be read: %1").arg(fn));
1542  return;
1543  }
1544  if (selectedScheme.isEmpty()) {
1545  QMessageBox::critical(this, tr("Error"), tr("Unknown open file scheme!"));
1546  return;
1547  }
1548 
1549  QUrl baseUrl = QUrl::fromLocalFile(fn);
1550  baseUrl.setScheme(selectedScheme);
1551  QStringList subreslist = KLFLibEngineFactory::listSubResources(baseUrl);
1552  for (k = 0; k < subreslist.size(); ++k) {
1553  QUrl url = baseUrl;
1554  url.addQueryItem("klfDefaultSubResource", subreslist[k]);
1555  bool r = openResource(url);
1556  if ( !r )
1557  QMessageBox::critical(this, tr("Error"), tr("Failed to open resource %1!").arg(url.toString()));
1558  }
1559 }
1560 
1562 {
1564 
1565  QList<QUrl> exportUrls;
1567  if (exportRes == NULL) {
1568  return false;
1569  }
1570  exportRes->setTitle(tr("Export %1").arg(QDateTime::currentDateTime()
1571  .toString(Qt::DefaultLocaleShortDate)));
1572 
1573  klfDbg("Export: to resource "<<exportRes->url().toString()<<". Export: "<<exportUrls);
1574 
1575  // visual feedback for export
1576  KLFProgressDialog pdlg(QString(), this);
1577  connect(exportRes, SIGNAL(operationStartReportingProgress(KLFProgressReporter *,
1578  const QString&)),
1579  &pdlg, SLOT(startReportingProgress(KLFProgressReporter *)));
1580  pdlg.setAutoClose(false);
1581  pdlg.setAutoReset(false);
1582 
1583  bool fail = false;
1584  QStringList subresources;
1585  int k;
1586  for (k = 0; k < exportUrls.size(); ++k) {
1587  klfDbg("Exporting "<<exportUrls[k]<<" ...");
1588  QUrl u = exportUrls[k];
1589  QString usr = u.hasQueryItem("klfDefaultSubResource")
1590  ? u.queryItemValue("klfDefaultSubResource")
1591  : QString();
1592  QString sr = usr;
1593  if (usr.isEmpty()) {
1594  // the resource doesn't support sub-resources
1595  usr = u.path().section('/', -1, -1, QString::SectionSkipEmpty); // last path element
1596  }
1597  usr.replace(QRegExp("[^a-zA-Z0-9_-]"), "_");
1598  QString subres = usr;
1599  int counter = 1;
1600  while (subresources.contains(subres))
1601  subres = usr+"_"+QString::number(counter++);
1602  // subres is the name of the subresource we will create
1603  bool r = exportRes->createSubResource(subres);
1604  if (!r) {
1605  fail = true;
1606  qWarning()<<KLF_FUNC_NAME<<" exporting "<<u<<" failed: can't create sub-resource "<<subres<<"!";
1607  continue;
1608  }
1609  subresources.append(subres);
1611  if (res == NULL) {
1612  fail = true;
1613  qWarning()<<KLF_FUNC_NAME<<" can't find open resource="<<u<<" !";
1614  continue;
1615  }
1616  QString title;
1617  if (usr.isEmpty()) {
1618  title = res->title();
1619  } else {
1621  title = res->title() + ": " +
1623  } else {
1624  title = res->title() + ": " + usr;
1625  }
1626  }
1628 
1629  pdlg.setDescriptiveText(tr("Exporting ... %3 (%1/%2)")
1630  .arg(k+1).arg(exportUrls.size()).arg(title));
1631 
1635  KLFLibEntryList elist;
1636  int j;
1637  for (j = 0; j < elistwid.size(); ++j)
1638  elist << elistwid[j].entry;
1639 
1640  QList<KLFLib::entryId> insertedIds = exportRes->insertEntries(subres, elist);
1641  if (!insertedIds.size() || insertedIds.contains(-1)) {
1642  QMessageBox::critical(this, tr("Error"), tr("Error exporting items!"));
1643  }
1644  }
1645 
1646  // remove our dummy sub-resource that was created with the resource
1647  // name was set in klflibbrowser_p.h: KLFLibExportDialog::showExportDi...()
1648  exportRes->deleteSubResource(QLatin1String("export_xtra"));
1649 
1650  // important, as it will cause save() to be called on legacy engines, otherwise we will just
1651  // have a zombie resource waiting for something
1652  delete exportRes;
1653 
1654  return !fail;
1655 }
1656 
1658 {
1660 
1661  // need to fetch selection from current view
1662  KLFAbstractLibView *view = curLibView();
1663  if (view == NULL) {
1664  qWarning("KLFLibBrowser::slotResourceProperties: NULL View!");
1665  return false;
1666  }
1667 
1668  // select and open target file
1670  if (factory == NULL) {
1671  qWarning()<<KLF_FUNC_NAME<<": Can't create KLFLibLegacyEngineFactory object (\"klf+legacy\") ?!?";
1672  return false;
1673  }
1674  QString filter = factory->schemeTitle(QLatin1String("klf+legacy")) + " (*.klf)";
1676  QString fileName = QFileDialog::getSaveFileName(this, tr("Export selection to file..."), path, filter);
1677 
1678  if (fileName.isEmpty()) {
1679  klfDbg("Canceled by user.");
1680  return false;
1681  }
1682 
1683  if (QFile::exists(fileName)) {
1684  // erase it. the file dialog already asked for overwrite confirmation.
1685  if ( ! QFile::remove(fileName) ) {
1686  QMessageBox::critical(this, tr("Error"), tr("Failed to overwrite file %1").arg(fileName));
1687  qWarning()<<KLF_FUNC_NAME<<": Can't overwrite file "<<fileName;
1688  return false;
1689  }
1690  }
1691 
1692  klfDbg("Exporting to file "<<fileName);
1693 
1694  // get selected entries
1695  KLFLibEntryList entryList = view->selectedEntries();
1696 
1697  // create file resource
1699  param["klfScheme"] = QLatin1String("klf+legacy");
1700  param["Filename"] = fileName;
1701  param["klfDefaultSubResource"] = tr("Export", "[[export selection default sub-resource name]]");
1702  KLFLibResourceEngine *resource = factory->createResource(QLatin1String("klf+legacy"), param, this);
1703 
1704  if (resource == NULL) {
1705  QMessageBox::critical(this, tr("Error"), tr("Failed to create export file %1!").arg(fileName));
1706  return false;
1707  }
1708 
1709  QList<KLFLib::entryId> insertedIds = resource->insertEntries(entryList);
1710  if (!insertedIds.size() || insertedIds.contains(-1)) {
1711  QMessageBox::critical(this, tr("Error"), tr("Error exporting items!"));
1712  }
1713 
1714  // important, as it will cause save() to be called on legacy engines, otherwise we will just
1715  // have a zombie resource waiting for something
1716  delete resource;
1717 
1718  return true;
1719 }
1720 
1722 {
1724  klfDbg( ": min,max="<<progressReporter->min()<<","<<progressReporter->max()
1725  <<"; text="<<text ) ;
1726 
1727  KLFProgressDialog *pdlg = new KLFProgressDialog(false, QString(), this);
1728 
1729  pdlg->startReportingProgress(progressReporter, text);
1730 
1731  pdlg->setProperty("klf_libbrowser_pdlg_want_hideautodelete", QVariant(true));
1732  pdlg->installEventFilter(this);
1733 }
1734 
1735 
1736 
1738 {
1739  if (e->type() == QEvent::KeyPress) {
1740  QKeyEvent *ke = (QKeyEvent*)e;
1741  if (ke->key() == Qt::Key_F8 && ke->modifiers() == 0) {
1742  hide();
1743  e->accept();
1744  return true;
1745  }
1746  }
1747  return QWidget::event(e);
1748 }
1749 
1751 {
1752  QWidget::timerEvent(event);
1753 }
1754 
1755 
1757 {
1758  // update some last-minute stuff
1759  // like the tab colors (which could have changed upon setting a skin)
1760  int k;
1761  for (k = 0; k < pLibViews.size(); ++k) {
1762  KLFLibBrowserViewContainer *viewc = pLibViews[k];
1763  KLFLibResourceEngine *resource = viewc->resourceEngine();
1764  u->tabResources->refreshTabReadOnly(u->tabResources->indexOf(viewc),
1766  }
1767  u->tabResources->setFocus();
1768  // and call superclass
1769  QWidget::showEvent(event);
1770 }
1771 
1772 
customContextMenuRequested(const QPoint &pos)
These flags are not stored, they act upon the openResource() call only.
Definition: klflibbrowser.h:62
This resource is the Archive resource.
Definition: klflibbrowser.h:57
void slotResourceRenameSubResource()
Instructs not to raise the tab during this call of openResource()
Definition: klflibbrowser.h:61
QList< QUrl > openUrls() const
setMenu(QMenu *menu)
KLFLibResourceEngine * resourceEngine()
QVariantMap saveGuiState() const
virtual bool canModifySubResourceProperty(const QString &subResource, int propId) const
Definition: klflib.cpp:548
static QUrl queryOpenResource(const QUrl &defaultlocation=QUrl(), QWidget *parent=0)
void slotUpdateForResourceProperty(KLFLibResourceEngine *resource, int propId)
virtual bool createSubResource(const QString &subResource, const QString &subResourceTitle)
Create a new sub-resource.
Definition: klflib.cpp:599
virtual QVariant subResourceProperty(const QString &subResource, int propId) const
Definition: klflib.cpp:528
void loadGuiState(const QVariantMap &v)
virtual bool canCreateLibView(const QString &viewTypeIdent, KLFLibResourceEngine *engine)=0
void slotCopyToResource()
KLFAbstractLibView * getView(const QUrl &url)
#define klfDbgT(streamableItems)
Sub-Resources may be assigned properties and values.
Definition: klflib.h:515
KLFConfig klfconfig
Definition: klfconfig.cpp:88
This resource is the History resource.
Definition: klflibbrowser.h:56
void slotStartProgress(KLFProgressReporter *progressReporter, const QString &text)
KLFLibResourceEngine * getOpenResource(const QUrl &url)
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
Resource &#39;Close&#39; GUI button is disabled (grayed)
Definition: klflibbrowser.h:54
void slotDefaultSubResourceChanged(const QString &subResource)
removeAt(int i)
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
mapToGlobal(const QPoint &pos)
virtual bool setSubResourceProperty(const QString &subResource, int propId, const QVariant &value)
Definition: klflib.cpp:593
#define klfDbg(streamableItems)
QList< QAction * > openSubResourceActions()
virtual KLFLibResourceEngine * openResource(const QUrl &location, QObject *parent=NULL)=0
#define KLF_DEBUG_BLOCK(msg)
void slotEntriesSelected(const KLFLibEntryList &entries)
virtual bool setViewType(const QString &viewType)
Definition: klflib.cpp:569
static bool canDecodeMimeData(const QMimeData *mimeData)
Definition: klflib.cpp:348
virtual bool setTitle(const QString &title)
set a new resource title for this library resource
Definition: klflib.cpp:555
join(const QString &separator)
hasQueryItem(const QString &key)
Instructs to not set new flags for already-open resources.
Definition: klflibbrowser.h:60
int min() const
bool openView(const QString &viewTypeIdent)
void requestRestore(const KLFLibEntry &entry, uint restoreFlags)
isEmpty()
toString(FormattingOptions options=None)
bool slotResourceNewSubRes()
addAction(const QString &text)
void slotMoveToResource()
KLFAbstractLibView * view()
void loadGuiState(const QVariantMap &state, bool openURLs=true)
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
virtual bool deleteSubResource(const QString &subResource)
Definition: klflib.cpp:612
static KLFLibViewFactory * findFactoryFor(const QString &viewTypeIdentifier)
Definition: klflibview.cpp:232
replace(int position, int n, const QString &after)
value(int i)
indexOf(const T &value, int from=0)
bool historyTagCopyToArchive
Definition: klfconfig.h:243
number(long n, int base=10)
void slotAddCategorySuggestions(const QStringList &catlist)
static QList< LocalFileType > localFileTypes()
QUrl currentUrl()
Returns the URL of the current tab page.
QColor colorNotFound
Definition: klfconfig.h:237
showEvent(QShowEvent *event)
bool slotResourceSaveTo()
virtual void restoreWithStyle()
Definition: klflibview.h:243
append(const T &value)
void timerEvent(QTimerEvent *event)
bool confirmClose
Definition: klfconfig.h:240
KLFLibBrowser(QWidget *parent=NULL)
static KLFLibResourceEngine * createResource(const QString &defaultWtype, QObject *resourceParent, QWidget *parent=0)
property(const char *name)
popup(const QPoint &p, QAction *atAction=0)
int currentUrlIndex()
Returns the index of currentUrl() in openUrls()
question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void slotCopyMoveToResource(QObject *sender, bool move)
KLFLibBrowserViewContainer * findOpenUrl(const QUrl &url)
removeAllQueryItems(const QString &key)
#define KLF_DEBUG_ASSIGN_REF_INSTANCE(object, ref_instance)
Data can be stored in separate sub-resources.
Definition: klflib.h:508
setScheme(const QString &scheme)
void slotResourcePropertyChanged(int propId)
virtual void wantMoreCategorySuggestions()
Definition: klflibview.cpp:195
void slotShowContextMenu(const QPoint &pos)
bool slotExportSelection()
A view widget to display a library resource&#39;s contents.
Definition: klflibview.h:82
virtual KLFLibResourceEngine * createResource(const QString &scheme, const Parameters &parameters, QObject *parent=NULL)
Create a new resource of given type and parameters.
Definition: klflib.cpp:1178
addSeparator()
void retranslateUi(bool alsoBaseUi=true)
void slotSubResourcePropertyChanged(const QString &subResource, int propId)
virtual bool canCreateSubResource() const
Definition: klflib.cpp:514
void slotResourceRenameFinished()
virtual bool deleteEntries(const QString &subResource, const QList< entryId > &idlist)=0
Delete some entries in this resource.
scheme()
void slotTabResourceShown(int tabIndex)
virtual QString defaultSubResource() const
Definition: klflib.cpp:504
Add a query item for default sub-res. as &quot;klfDefaultSubResource&quot;.
Definition: klflib.h:555
void libEntriesSelected(const KLFLibEntryList &entries)
#define KLF_DEBUG_TIME_BLOCK(msg)
#define klfFmtCC
virtual QUrl url() const =0
Display Resource URL. NOT exactly like KLFLibResourceEngine::url() !
virtual uint supportedFeatureFlags() const
List of features supported by this resource engine.
Definition: klflib.h:550
virtual bool canModifyData(const QString &subResource, ModifyType modifytype) const
Definition: klflib.cpp:472
KLFAbstractLibView * curLibView()
#define KLF_FUNC_NAME
virtual KLFLibEntryList selectedEntries() const =0
setParent(QObject *parent)
virtual QList< entryId > insertEntries(const QString &subResource, const KLFLibEntryList &entrylist)=0
Insert new entries in this resource.
void slotResourceProperties()
Tags about the equation (string)
Definition: klflib.h:67
static QString guessLocalFileScheme(const QString &fileName)
virtual QString viewType() const
The (last) View Type used to display this resource.
Definition: klflib.h:613
contains(const T &value)
virtual QString title() const
The human-set title of this resource.
Definition: klflib.h:599
void slotRestoreWithStyle()
virtual void restoreLatexOnly()
Definition: klflibview.h:245
KLFLibBrowserViewContainer * curView()
static bool decodeMimeData(const QMimeData *mimeData, KLFLibEntryList *entryList, QVariantMap *metaData)
Definition: klflib.cpp:360
static QString createSubResourceIn(KLFLibResourceEngine *resource, QWidget *parent=0)
static QStringList listSubResources(const QUrl &url)
Definition: klflib.cpp:1231
KLFLibBrowserViewContainer * findSpecialResource(uint specialResourceRoleFlag)
bool slotResourceDelSubRes()
QString lastFileDialogPath
Definition: klfconfig.h:244
void setResourceRoleFlags(uint flags)
void slotShowTabContextMenu(const QPoint &pos)
An entry (single formula) in the library.
Definition: klflib.h:55
bool closeResource(const QUrl &url)
bool openResourceFromGuiState(const QUrl &url, const QVariantMap &guiState)
bool slotResourceClose(KLFLibBrowserViewContainer *view=NULL, bool force=false)
static KLFLibEngineFactory * findFactoryFor(const QUrl &url)
Definition: klflib.cpp:1163
static QString displayTitle(KLFLibResourceEngine *resource)
addMenu(QMenu *menu)
void slotDeleteSelected()
void slotRefreshResourceActionsEnabled()
virtual KLFLibResourceEngine * resourceEngine() const
Definition: klflibview.h:89
getSaveFileName(QWidget *parent=0, const QString &caption=QString()
virtual bool changeEntries(const QString &subResource, const QList< entryId > &idlist, const QList< int > &properties, const QList< QVariant > &values)=0
Change some entries in this resource.
critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void requestRestoreStyle(const KLFStyle &style)
bool slotResourceOpen()
virtual QList< KLFLibEntryWithId > allEntries(const QString &subResource, const QList< int > &wantedEntryProperties=QList< int >())=0
query all entries in this resource
KLFLibBrowserViewContainer * findOpenResource(KLFLibResourceEngine *resource)
addQueryItem(const QString &key, const QString &value)
warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
indexOf(const QRegExp &rx, int from=0)
int max() const
static QString defaultViewTypeIdentifier()
Definition: klflibview.cpp:225
QColor colorFound
Definition: klfconfig.h:236
isEmpty()
virtual QList< KLFLib::entryId > selectedEntryIds() const =0
static KLFLibResourceEngine * showExportDialogCreateResource(KLFLibBrowser *libbrowser, QList< QUrl > *exportUrls)
getOpenFileName(QWidget *parent=0, const QString &caption=QString()
virtual QUrl url(uint flags=0x0) const
query URL
Definition: klflib.cpp:457
QList< KLFLibBrowserViewContainer * > findByRoleFlags(uint flags, uint mask)
KLFLibBrowserViewContainer * viewForTabIndex(int tab)
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
virtual QString suggestedViewTypeIdentifier() const
Definition: klflib.h:704
An abstract resource engine.
Definition: klflib.h:440
virtual QList< QAction * > addContextMenuActions(const QPoint &pos)
Definition: klflibview.cpp:200
struct KLFConfig::@4 LibraryBrowser
bool openResource(const QUrl &url, uint resourceRoleFlags=NoChangeFlag, const QString &viewTypeIdentifier=QString())
static QMimeData * createMimeData(const KLFLibEntryList &entryList, const QVariantMap &metaData)
Creates a QMetaData with all known registered encoding mime types.
Definition: klflib.cpp:326
void showEvent(QShowEvent *event)
Implements the saveTo() function.
Definition: klflib.h:504
void slotMetaInfoChanged(const QMap< int, QVariant > &props)
virtual bool canDeleteSubResource(const QString &subResource) const
Definition: klflib.cpp:523
void slotRestoreLatexOnly()
event(QEvent *event)
virtual bool canModifyProp(int propId) const
Definition: klflib.cpp:485
bool event(QEvent *event)
QVariantMap saveGuiState()
queryItemValue(const QString &key)
virtual QString schemeTitle(const QString &scheme) const =0
virtual ~KLFLibBrowser()
fromLocalFile(const QString &localFile)
virtual bool eventFilter(QObject *object, QEvent *event)
void resourceTabChanged(const QUrl &currentUrl)
QList< QAction * > viewTypeActions() const
void slotResourceDataChanged(const QList< KLFLib::entryId > &entryIdList)
bool slotResourceNew()
void slotResourceRename()
virtual bool selectEntries(const QList< KLFLib::entryId > &idList)=0

Generated by doxygen 1.8.5