"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bUtils.cpp" (12 Feb 2021, 1309 Bytes) of package /linux/privat/cb2bib-2.0.1.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 "c2bUtils.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #include "c2bUtils.h"
    8 
    9 #include <QDesktopServices>
   10 #include <QMessageBox>
   11 
   12 
   13 namespace c2bUtils
   14 {
   15 
   16 bool openFile(const QString& fn, QWidget* w)
   17 {
   18     // URL fn is decoded always, in the hope of making openFile encoding agnostic
   19     const QString decoded(QUrl::fromPercentEncoding(fn.toUtf8()));
   20     const QUrl url(stringToUrl(decoded));
   21     if (!url.isValid())
   22     {
   23         if (w)
   24             QMessageBox::warning(w, QObject::tr("Warning - cb2Bib"),
   25                                  QObject::tr("Unable to open file.\nError: URL '%1' is not valid.").arg(url.toString()),
   26                                  QMessageBox::Ok);
   27         return false;
   28     }
   29     if (!QDesktopServices::openUrl(url))
   30     {
   31         if (w)
   32             QMessageBox::warning(w, QObject::tr("Warning - cb2Bib"), QObject::tr("Unable to open file '%1'.").arg(fn),
   33                                  QMessageBox::Ok);
   34         return false;
   35     }
   36     return true;
   37 }
   38 
   39 } // namespace c2bUtils