"Fossies" - the Fresh Open Source Software Archive 
Member "cb2bib-2.0.1/src/bookmarkPlugin.cpp" (12 Feb 2021, 3907 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 "bookmarkPlugin.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 "bookmarkPlugin.h"
8
9 #include "c2b.h"
10 #include "c2bFileSystemWatcher.h"
11 #include "c2bSettings.h"
12 #include "c2bUtils.h"
13
14 #include <QtGui>
15
16
17 bookmarkPlugin::bookmarkPlugin(QWidget* parentw) : QMenu(parentw)
18 {
19 setObjectName(QString::fromUtf8("menuBookmarks"));
20 setTitle(QApplication::translate("c2bEditor", "&Bookmarks", 0));
21 connect(c2bSettingsP, SIGNAL(newSettings()), this, SLOT(init()));
22 _fsw = new c2bFileSystemWatcher(this);
23 connect(_fsw, SIGNAL(fileChanged(QString)), this, SLOT(parseBookmarks()));
24 init();
25 }
26
27 bookmarkPlugin::~bookmarkPlugin() {}
28
29
30 void bookmarkPlugin::init()
31 {
32 const QString nfn(c2bSettingsP->fileName("cb2Bib/NetworkFile"));
33 if (nfn == _bookmark_file)
34 return;
35 if (QFileInfo::exists(nfn))
36 {
37 if (!_bookmark_file.isEmpty())
38 _fsw->removePath(_bookmark_file);
39 _bookmark_file = nfn;
40 _fsw->addPath(_bookmark_file);
41 }
42 parseBookmarks();
43 }
44
45 void bookmarkPlugin::parseBookmarks()
46 {
47 clear();
48 const QString bmf(c2bUtils::fileToString(_bookmark_file));
49 QStringList bookmarks(bmf.split(QRegExp("[\\r\\n]"), QString::KeepEmptyParts));
50 const QRegExp _bookmark("^editorbookmark=");
51 const QRegExp _separator("^editorbookmark=\\s*$");
52 for (int i = 0; i < bookmarks.count(); ++i)
53 {
54 if (bookmarks.at(i).contains(_separator))
55 {
56 addSeparator();
57 continue;
58 }
59 if (bookmarks.at(i).contains(_bookmark))
60 {
61 bookmarks[i].remove(_bookmark);
62 const QStringList bm_parts(bookmarks.at(i).split('|', QString::KeepEmptyParts));
63 if (bm_parts.count() != 4)
64 {
65 c2bUtils::warn(tr("bookmarkPlugin::parseBookmarks: Syntax error at '%1'").arg(bookmarks.at(i)));
66 continue;
67 }
68 QAction* act = addAction(bm_parts.at(0), this, SLOT(openBookmark()));
69 act->setData(bm_parts.at(1));
70 act->setStatusTip(QString("%1 [%2]").arg(bm_parts.at(0), bm_parts.at(1)));
71 act->setShortcut(bm_parts.at(2));
72 act->setIcon(QIcon(iconProvider(bm_parts.at(1), bm_parts.at(3))));
73 }
74 }
75 addSeparator();
76 QAction* edit_bookmarks = addAction(tr("Edit Bookmarks"), this, SIGNAL(editBookmarks()));
77 edit_bookmarks->setStatusTip(tr("Edit bookmarks"));
78 edit_bookmarks->setIcon(QIcon(":/icons/icons/edit.png"));
79 }
80
81 QString bookmarkPlugin::iconProvider(const QString& fn, const QString& iconFile)
82 {
83 if (!iconFile.isEmpty())
84 return iconFile;
85 if (fn.contains(QRegExp("\\.(tex|dvi)\\b", Qt::CaseInsensitive)))
86 return ":/icons/icons/application-x-tex.png";
87 if (fn.contains(QRegExp("\\.(chm|djvu|pdf|ps)\\b", Qt::CaseInsensitive)))
88 return ":/icons/icons/application-x-pdf.png";
89 if (fn.contains(QRegExp("\\.(htm|html|php)\\b", Qt::CaseInsensitive)))
90 return ":/icons/icons/application-x-html.png";
91 if (fn.contains(QRegExp("\\.txt\\b", Qt::CaseInsensitive)))
92 return ":/icons/icons/application-x-tex.png";
93 if (fn.contains(QRegExp("\\.bib\\b", Qt::CaseInsensitive)))
94 return ":/icons/icons/cb2bib.png";
95 return ":/icons/icons/application-x-none.png";
96 }
97
98 void bookmarkPlugin::openBookmark()
99 {
100 QAction* act = static_cast<QAction*>(sender());
101 if (act)
102 {
103 const QString fn(act->data().toString());
104 if (fn.endsWith(".bib")) // Open BiBTeX files internally
105 emit openFile(fn);
106 else
107 c2bUtils::openFile(fn, parentWidget());
108 }
109 }