"Fossies" - the Fresh Open Source Software Archive 
Member "cb2bib-2.0.1/src/c2b.cpp" (12 Feb 2021, 4443 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 "c2b.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 "c2b.h"
8
9 #include "c2bClipboard.h"
10 #include "c2bConfigure.h"
11 #include "dialog.h"
12 #include "ui_proxyDialog.h"
13
14 #include <QAuthenticator>
15 #include <QMessageBox>
16 #include <QNetworkProxy>
17 #include <QProgressDialog>
18
19
20 /**
21 Global resources for cb2Bib
22 */
23 c2b::c2b(QWidget* main, QObject* parento) : QObject(parento)
24 {
25 Q_ASSERT_X(!_c2b_single_instance, "c2b", "cb2Bib resources already instantiated");
26 c2b::_c2b_single_instance = this;
27 _c2b_main = main;
28
29 if (_c2b_main->inherits("cb2Bib"))
30 {
31 // Create bibliographic parser
32 _c2b_bibparser = new c2bBibParser(this);
33
34 // Create cb2Bib network
35 _c2b_network = new network(this);
36 connect(_c2b_network, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this,
37 SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
38 connect(_c2b_network, SIGNAL(downloadProgress(qint64,qint64)), this,
39 SLOT(updateDownloadProgress(qint64,qint64)));
40 _download_progress = new QProgressDialog(_c2b_main, dialog::flags);
41 _download_progress->setWindowTitle("Downloading...");
42 _download_progress->reset();
43 connect(_download_progress, SIGNAL(canceled()), _c2b_network, SLOT(cancelDownload()));
44
45 // Create cb2Bib network query info
46 _c2b_netqinf = new c2bNetworkQueryInfo(this);
47
48 // Create cb2Bib metadata parser
49 _c2b_metadataparser = new metadataParser(_c2b_bibparser, this);
50 connect(_c2b_metadataparser, SIGNAL(showMessage(QString,QString)), this, SLOT(showMessage(QString,QString)));
51
52 // Create cb2Bib clipboard
53 _c2b_clipboard = new c2bClipboard(this);
54 _c2b_clipboard->setConnected(true);
55 }
56 else if (_c2b_main->inherits("c2bAnnote"))
57 {
58 // Nothing is needed at present for the c2bAnnote
59 }
60 else
61 Q_ASSERT_X(false, "c2b", "unknown required resources for main");
62 }
63
64 c2b::~c2b()
65 {
66 _c2b_single_instance = 0;
67 }
68
69
70 c2b* c2b::_c2b_single_instance = 0;
71
72
73 void c2b::showMessage(const QString& title, const QString& ms)
74 {
75 QMessageBox::warning(_c2b_main, title, ms, QMessageBox::Ok);
76 }
77
78 void c2b::configure(int index)
79 {
80 c2bConfigure* c = new c2bConfigure();
81 if (index > -1)
82 c->setPage(index);
83 if (c->exec() == QDialog::Accepted)
84 showMessage(tr("Configuration was saved."));
85 else
86 showMessage(tr("Configuration was cancelled."));
87 delete c;
88 }
89
90 void c2b::exitRequested()
91 {
92 foreach (QWidget* w, QApplication::topLevelWidgets())
93 {
94 // So far only editors grant user exit cancellation
95 // Avoid closing other visible widgets until exit is granted
96 if (w->isVisible())
97 if (w->inherits("c2bEditor"))
98 w->close();
99 }
100 qApp->processEvents();
101 foreach (QWidget* widget, QApplication::topLevelWidgets())
102 {
103 if (widget->isVisible())
104 if (widget->inherits("c2bEditor"))
105 return;
106 }
107 qApp->closeAllWindows();
108 qApp->processEvents();
109 if (!qApp->quitOnLastWindowClosed())
110 qApp->quit();
111 }
112
113 void c2b::updateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
114 {
115 if (bytesTotal < 50000)
116 return;
117 if (bytesReceived == bytesTotal)
118 {
119 _download_progress->reset();
120 return;
121 }
122 _download_progress->setLabelText(tr("Retrieving from %1...").arg(QUrl(_c2b_network->sourceFilename()).host()));
123 _download_progress->setMaximum((int)bytesTotal);
124 _download_progress->setValue((int)bytesReceived);
125 }
126
127 void c2b::proxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* auth)
128 {
129 QDialog dialog(_c2b_main, dialog::flags);
130 Ui::proxyDialog proxyDialog;
131 proxyDialog.setupUi(&dialog);
132 dialog.setWindowTitle(tr("Proxy %1 Authentication - cb2Bib").arg(proxy.hostName()));
133 if (dialog.exec() == QDialog::Accepted)
134 {
135 auth->setUser(proxyDialog.userNameLineEdit->text());
136 auth->setPassword(proxyDialog.passwordLineEdit->text());
137 }
138 else
139 _c2b_network->cancelDownload();
140 }