"Fossies" - the Fresh Open Source Software Archive

Member "recoll-1.26.3/qtgui/rclm_wins.cpp" (24 Nov 2019, 13910 Bytes) of package /linux/privat/recoll-1.26.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "rclm_wins.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.25.23_vs_1.26.0.

    1 /* Copyright (C) 2005-2019 J.F.Dockes
    2  *   This program is free software; you can redistribute it and/or modify
    3  *   it under the terms of the GNU General Public License as published by
    4  *   the Free Software Foundation; either version 2 of the License, or
    5  *   (at your option) any later version.
    6  *
    7  *   This program is distributed in the hope that it will be useful,
    8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  *   GNU General Public License for more details.
   11  *
   12  *   You should have received a copy of the GNU General Public License
   13  *   along with this program; if not, write to the
   14  *   Free Software Foundation, Inc.,
   15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   16  */
   17 #include "autoconfig.h"
   18 
   19 #include <QShortcut>
   20 #include <QMessageBox>
   21 
   22 #include "log.h"
   23 #include "internfile.h"
   24 #include "listdialog.h"
   25 #include "confgui/confguiindex.h"
   26 #include "idxsched.h"
   27 #ifdef _WIN32
   28 #include "winschedtool.h"
   29 #else
   30 #include "crontool.h"
   31 #include "rtitool.h"
   32 #endif
   33 #include "snippets_w.h"
   34 #include "fragbuts.h"
   35 #include "specialindex.h"
   36 #include "rclmain_w.h"
   37 #include "webcache.h"
   38 #include "restable.h"
   39 
   40 using namespace std;
   41 
   42 static const QKeySequence quitKeySeq("Ctrl+q");
   43 static const QKeySequence closeKeySeq("Ctrl+w");
   44 
   45 // Open advanced search dialog.
   46 void RclMain::showAdvSearchDialog()
   47 {
   48     if (asearchform == 0) {
   49     asearchform = new AdvSearch(0);
   50         if (asearchform == 0) {
   51             return;
   52         }
   53     connect(new QShortcut(quitKeySeq, asearchform), SIGNAL (activated()), 
   54         this, SLOT (fileExit()));
   55 
   56     connect(asearchform, 
   57         SIGNAL(startSearch(std::shared_ptr<Rcl::SearchData>, bool)), 
   58         this, SLOT(startSearch(std::shared_ptr<Rcl::SearchData>, bool)));
   59         connect(asearchform, SIGNAL(setDescription(QString)), 
   60                 this, SLOT(onSetDescription(QString)));
   61     asearchform->show();
   62     } else {
   63     // Close and reopen, in hope that makes us visible...
   64     asearchform->close();
   65     asearchform->show();
   66     }
   67 }
   68 
   69 void RclMain::showSpellDialog()
   70 {
   71     if (spellform == 0) {
   72     spellform = new SpellW(0);
   73     connect(new QShortcut(quitKeySeq, spellform), SIGNAL (activated()), 
   74         this, SLOT (fileExit()));
   75     connect(spellform, SIGNAL(wordSelect(QString)),
   76         sSearch, SLOT(addTerm(QString)));
   77     spellform->show();
   78     } else {
   79     // Close and reopen, in hope that makes us visible...
   80     spellform->close();
   81         spellform->show();
   82     }
   83 }
   84 
   85 void RclMain::showWebcacheDialog()
   86 {
   87     switch (indexerState()) {
   88     case RclMain::IXST_UNKNOWN:
   89         QMessageBox::warning(0, "Recoll", tr("Unknown indexer state. "
   90                                              "Can't access webcache file."));
   91         return;
   92     case RclMain::IXST_RUNNINGMINE:
   93     case RclMain::IXST_RUNNINGNOTMINE:
   94         QMessageBox::warning(0, "Recoll", tr("Indexer is running. "
   95                                              "Can't access webcache file."));
   96         return;
   97     case RclMain::IXST_NOTRUNNING:
   98         break;
   99     }
  100 
  101     if (!m_pidfile) {
  102         m_pidfile = new Pidfile(theconfig->getPidfile());
  103         if (m_pidfile->open() != 0) {
  104             deleteZ(m_pidfile);
  105             return;
  106         }
  107         if (m_pidfile->write_pid() != 0) {
  108             deleteZ(m_pidfile);
  109             return;
  110         }
  111     }
  112     
  113     if (webcache == 0) {
  114     webcache = new WebcacheEdit(this);
  115         webcache->setAttribute(Qt::WA_DeleteOnClose);
  116         connect(new QShortcut(quitKeySeq, webcache), SIGNAL (activated()), 
  117         this, SLOT (fileExit()));
  118         connect(webcache, SIGNAL(destroyed(QObject*)),
  119                 this, SLOT(onWebcacheDestroyed(QObject*)) );
  120         webcache->show();
  121     }
  122 }
  123 void RclMain::onWebcacheDestroyed(QObject *)
  124 {
  125     deleteZ(m_pidfile);
  126     webcache = 0;
  127 }
  128 
  129 void RclMain::showIndexStatistics()
  130 {
  131     showSpellDialog();
  132     if (spellform == 0)
  133         return;
  134     spellform->setMode(SpellW::TYPECMB_STATS);
  135 }
  136 
  137 void RclMain::showFragButs()
  138 {
  139     if (fragbuts && fragbuts->isStale(0)) {
  140         deleteZ(fragbuts);
  141     }
  142     if (fragbuts == 0) {
  143     fragbuts = new FragButs(0);
  144         if (fragbuts->ok()) {
  145             fragbuts->show();
  146             connect(fragbuts, SIGNAL(fragmentsChanged()),
  147                     this, SLOT(onFragmentsChanged()));
  148         } else {
  149             deleteZ(fragbuts);
  150         }
  151     } else {
  152     // Close and reopen, in hope that makes us visible...
  153     fragbuts->close();
  154         fragbuts->show();
  155     }
  156 }
  157 
  158 void RclMain::showSpecIdx()
  159 {
  160     if (specidx == 0) {
  161     specidx = new SpecIdxW(0);
  162         connect(specidx, SIGNAL(accepted()), this, SLOT(specialIndex()));
  163         specidx->show();
  164     } else {
  165     // Close and reopen, in hope that makes us visible...
  166     specidx->close();
  167         specidx->show();
  168     }
  169 }
  170 
  171 void RclMain::showIndexConfig()
  172 {
  173     showIndexConfig(false);
  174 }
  175 void RclMain::execIndexConfig()
  176 {
  177     showIndexConfig(true);
  178 }
  179 void RclMain::showIndexConfig(bool modal)
  180 {
  181     LOGDEB("showIndexConfig()\n" );
  182     bool created{false};
  183     if (indexConfig == 0) {
  184         created = true;
  185     indexConfig = new ConfIndexW(0, theconfig);
  186     }
  187     indexConfig->showPrefs(modal);
  188     if (created) {
  189     connect(new QShortcut(quitKeySeq, indexConfig->getDialog()),
  190                 SIGNAL (activated()), this, SLOT (fileExit()));
  191     }
  192 }
  193 
  194 void RclMain::showIndexSched()
  195 {
  196     showIndexSched(false);
  197 }
  198 void RclMain::execIndexSched()
  199 {
  200     showIndexSched(true);
  201 }
  202 void RclMain::showIndexSched(bool modal)
  203 {
  204     LOGDEB("showIndexSched()\n" );
  205     if (indexSched == 0) {
  206     indexSched = new IdxSchedW(this);
  207     connect(new QShortcut(quitKeySeq, indexSched), SIGNAL (activated()), 
  208         this, SLOT (fileExit()));
  209 #ifdef _WIN32
  210         indexSched->cronCLB->setText(tr("Batch scheduling"));
  211         indexSched->cronCLB->setDescription(
  212             tr("The tool will let you decide at what time indexing should run. "
  213                " It uses the Windows task scheduler."));
  214         indexSched->mainExplainLBL->hide();
  215         indexSched->rtidxCLB->hide();
  216 #endif
  217     connect(indexSched->cronCLB, SIGNAL(clicked()), 
  218         this, SLOT(execCronTool()));
  219     if (theconfig && theconfig->isDefaultConfig()) {
  220 #ifdef RCL_MONITOR
  221         connect(indexSched->rtidxCLB, SIGNAL(clicked()), 
  222             this, SLOT(execRTITool()));
  223 #else
  224         indexSched->rtidxCLB->setEnabled(false);
  225         indexSched->rtidxCLB->setToolTip(tr("Disabled because the real time indexer was not compiled in."));
  226 #endif
  227     } else {
  228         indexSched->rtidxCLB->setEnabled(false);
  229         indexSched->rtidxCLB->setToolTip(tr("This configuration tool only works for the main index."));
  230     }
  231     } else {
  232     // Close and reopen, in hope that makes us visible...
  233     indexSched->close();
  234     }
  235     if (modal) {
  236     indexSched->exec();
  237     indexSched->setModal(false);
  238     } else {
  239     indexSched->show();
  240     }
  241 }
  242 
  243 void RclMain::showCronTool()
  244 {
  245     showCronTool(false);
  246 }
  247 void RclMain::execCronTool()
  248 {
  249     showCronTool(true);
  250 }
  251 
  252 void RclMain::showCronTool(bool modal)
  253 {
  254     LOGDEB("showCronTool()\n" );
  255     if (cronTool == 0) {
  256 #ifdef _WIN32
  257     cronTool = new WinSchedToolW(0);
  258 #else
  259     cronTool = new CronToolW(0);
  260 #endif
  261     connect(new QShortcut(quitKeySeq, cronTool), SIGNAL (activated()), 
  262         this, SLOT (fileExit()));
  263     } else {
  264     // Close and reopen, in hope that makes us visible...
  265     cronTool->close();
  266     }
  267     if (modal) {
  268     cronTool->exec();
  269     cronTool->setModal(false);
  270     } else {
  271     cronTool->show();
  272     }
  273 }
  274 
  275 void RclMain::showRTITool()
  276 {
  277     showRTITool(false);
  278 }
  279 void RclMain::execRTITool()
  280 {
  281     showRTITool(true);
  282 }
  283 void RclMain::showRTITool(bool modal)
  284 {
  285 #ifndef _WIN32
  286     LOGDEB("showRTITool()\n" );
  287     if (rtiTool == 0) {
  288     rtiTool = new RTIToolW(0);
  289     connect(new QShortcut(quitKeySeq, rtiTool), SIGNAL (activated()), 
  290         this, SLOT (fileExit()));
  291     } else {
  292     // Close and reopen, in hope that makes us visible...
  293     rtiTool->close();
  294     }
  295     if (modal) {
  296     rtiTool->exec();
  297     rtiTool->setModal(false);
  298     } else {
  299     rtiTool->show();
  300     }
  301 #endif
  302 }
  303 
  304 void RclMain::showUIPrefs()
  305 {
  306     if (uiprefs == 0) {
  307     uiprefs = new UIPrefsDialog(this);
  308     connect(new QShortcut(quitKeySeq, uiprefs), SIGNAL (activated()), 
  309         this, SLOT (fileExit()));
  310     connect(uiprefs, SIGNAL(uiprefsDone()), this, SLOT(setUIPrefs()));
  311     connect(this, SIGNAL(stemLangChanged(const QString&)), 
  312         uiprefs, SLOT(setStemLang(const QString&)));
  313     } else {
  314     // Close and reopen, in hope that makes us visible...
  315     uiprefs->close();
  316         rwSettings(false);
  317         uiprefs->setFromPrefs();
  318     }
  319     uiprefs->show();
  320 }
  321 
  322 void RclMain::showExtIdxDialog()
  323 {
  324     showUIPrefs();
  325     uiprefs->tabWidget->setCurrentIndex(3);
  326 }
  327 
  328 void RclMain::showAboutDialog()
  329 {
  330     string vstring = Rcl::version_string() +
  331         string("<br><a href='http://www.recoll.org'>www.recoll.org</a>") +
  332     string("<br><a href='http://www.xapian.org'>www.xapian.org</a>");
  333     QMessageBox::information(this, tr("About Recoll"), vstring.c_str());
  334 }
  335 
  336 void RclMain::showMissingHelpers()
  337 {
  338     string miss;
  339     if (!theconfig->getMissingHelperDesc(miss)) {
  340     QMessageBox::information(
  341             this, "", tr("No information: initial indexing not yet performed."));
  342     return;
  343     }
  344     QString msg = QString::fromUtf8("<p>") +
  345     tr("External applications/commands needed for your file types "
  346        "and not found, as stored by the last indexing pass in ");
  347     msg += "<i>";
  348     msg += QString::fromLocal8Bit(theconfig->getConfDir().c_str());
  349     msg += "/missing</i>:<pre>\n";
  350     if (!miss.empty()) {
  351     msg += QString::fromUtf8(miss.c_str());
  352     } else {
  353     msg += tr("No helpers found missing");
  354     }
  355     msg += "</pre>";
  356     QMessageBox::information(this, tr("Missing helper programs"), msg);
  357 }
  358 
  359 void RclMain::showActiveTypes()
  360 {
  361     string reason;
  362     bool maindberror;
  363     if (!maybeOpenDb(reason, true, &maindberror)) {
  364     QMessageBox::warning(0, tr("Error"), 
  365                  u8s2qs(reason),
  366                  QMessageBox::Ok, 
  367                  QMessageBox::NoButton);
  368     return;
  369     }
  370 
  371     // All mime types in index. 
  372     vector<string> vdbtypes;
  373     if (!rcldb->getAllDbMimeTypes(vdbtypes)) {
  374     QMessageBox::warning(0, tr("Error"), 
  375                  tr("Index query error"),
  376                  QMessageBox::Ok, 
  377                  QMessageBox::NoButton);
  378     return;
  379     }
  380     set<string> mtypesfromdb;
  381     mtypesfromdb.insert(vdbtypes.begin(), vdbtypes.end());
  382 
  383     // All types listed in mimeconf:
  384     vector<string> mtypesfromconfig = theconfig->getAllMimeTypes();
  385 
  386     // Intersect file system types with config types (those not in the
  387     // config can be indexed by name, not by content)
  388     set<string> mtypesfromdbconf;
  389     for (vector<string>::const_iterator it = mtypesfromconfig.begin();
  390      it != mtypesfromconfig.end(); it++) {
  391     if (mtypesfromdb.find(*it) != mtypesfromdb.end())
  392         mtypesfromdbconf.insert(*it);
  393     }
  394 
  395     // Substract the types for missing helpers (the docs are indexed
  396     // by name only):
  397     string miss;
  398     if (theconfig->getMissingHelperDesc(miss) && !miss.empty()) {
  399     FIMissingStore st(miss);
  400     map<string, set<string> >::const_iterator it;
  401     for (it = st.m_typesForMissing.begin(); 
  402          it != st.m_typesForMissing.end(); it++) {
  403         set<string>::const_iterator it1;
  404         for (it1 = it->second.begin(); 
  405          it1 != it->second.end(); it1++) {
  406         set<string>::iterator it2 = mtypesfromdbconf.find(*it1);
  407         if (it2 != mtypesfromdbconf.end())
  408             mtypesfromdbconf.erase(it2);
  409         }
  410     }   
  411     }
  412     ListDialog dialog;
  413     dialog.setWindowTitle(tr("Indexed MIME Types"));
  414 
  415     // Turn the result into a string and display
  416     dialog.groupBox->setTitle(tr("Content has been indexed for these MIME types:"));
  417 
  418     // We replace the list with an editor so that the user can copy/paste
  419     delete dialog.listWidget;
  420     QTextEdit *editor = new QTextEdit(dialog.groupBox);
  421     editor->setReadOnly(true);
  422     dialog.horizontalLayout->addWidget(editor);
  423 
  424     if (mtypesfromdbconf.empty()) {
  425     editor->append(tr("Types list empty: maybe wait for indexing to "
  426                           "progress?"));
  427     } else {
  428         for (set<string>::const_iterator it = mtypesfromdbconf.begin(); 
  429              it != mtypesfromdbconf.end(); it++) {
  430             editor->append(QString::fromUtf8(it->c_str()));
  431         }
  432     }
  433     editor->moveCursor(QTextCursor::Start);
  434     editor->ensureCursorVisible();
  435     dialog.exec();
  436 }
  437 
  438 void RclMain::newDupsW(const Rcl::Doc, const vector<Rcl::Doc> dups)
  439 {
  440     ListDialog dialog;
  441     dialog.setWindowTitle(tr("Duplicate documents"));
  442 
  443     dialog.groupBox->setTitle(tr("These Urls ( | ipath) share the same"
  444                  " content:"));
  445     // We replace the list with an editor so that the user can copy/paste
  446     delete dialog.listWidget;
  447     QTextEdit *editor = new QTextEdit(dialog.groupBox);
  448     editor->setReadOnly(true);
  449     dialog.horizontalLayout->addWidget(editor);
  450 
  451     for (vector<Rcl::Doc>::const_iterator it = dups.begin(); 
  452      it != dups.end(); it++) {
  453     if (it->ipath.empty()) 
  454         editor->append(QString::fromLocal8Bit(it->url.c_str()));
  455     else 
  456         editor->append(QString::fromLocal8Bit(it->url.c_str()) + " | " +
  457                QString::fromUtf8(it->ipath.c_str()));
  458     }
  459     editor->moveCursor(QTextCursor::Start);
  460     editor->ensureCursorVisible();
  461     dialog.exec();
  462 }
  463 
  464 void RclMain::showSnippets(Rcl::Doc doc)
  465 {
  466     if (!m_snippets) {
  467         m_snippets = new SnippetsW(doc, m_source);
  468         connect(m_snippets, SIGNAL(startNativeViewer(Rcl::Doc, int, QString)),
  469                 this, SLOT(startNativeViewer(Rcl::Doc, int, QString)));
  470         connect(new QShortcut(quitKeySeq, m_snippets), SIGNAL (activated()), 
  471                 this, SLOT (fileExit()));
  472         connect(new QShortcut(closeKeySeq, m_snippets), SIGNAL (activated()), 
  473                 m_snippets, SLOT (close()));
  474         if (restable) {
  475             connect(
  476                 restable,
  477                 SIGNAL(detailDocChanged(Rcl::Doc, std::shared_ptr<DocSequence>)),
  478                 m_snippets,
  479                 SLOT(onSetDoc(Rcl::Doc, std::shared_ptr<DocSequence>)));
  480         }
  481     } else {
  482         m_snippets->onSetDoc(doc, m_source);
  483     }
  484     m_snippets->show();
  485 }