Changeset View
Changeset View
Standalone View
Standalone View
src/elisautils.cpp
Show All 11 Lines | |||||
12 | * Lesser General Public License for more details. | 12 | * Lesser General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "elisautils.h" | 18 | #include "elisautils.h" | ||
19 | 19 | | |||
20 | #include <QUrl> | ||||
21 | #include <QEventLoop> | ||||
22 | #include <QNetworkAccessManager> | ||||
23 | #include <QNetworkReply> | ||||
24 | #include <QFile> | ||||
25 | | ||||
26 | bool ElisaUtils::checkUrl(QVariant name) { | ||||
27 | QUrl url = name.toUrl(); | ||||
28 | if(url.isEmpty()) { | ||||
29 | return true; | ||||
30 | } | ||||
31 | | ||||
32 | if(url.isLocalFile()) { | ||||
33 | QFile file(name.toString().mid(QStringLiteral("file:/").size())); | ||||
34 | return file.exists(); | ||||
35 | } | ||||
36 | | ||||
37 | QNetworkAccessManager qNetworkAccessManager; | ||||
38 | QNetworkRequest request; | ||||
39 | request.setUrl(url); | ||||
40 | | ||||
41 | QEventLoop signalWaitLoop; | ||||
42 | QObject::connect(&qNetworkAccessManager, SIGNAL(finished(QNetworkReply*)),&signalWaitLoop, SLOT(quit())); | ||||
astippich: If this is gonna be used, please use the new connect syntax. There are plenty of examples… | |||||
43 | QNetworkReply *response = qNetworkAccessManager.head(request); | ||||
44 | signalWaitLoop.exec(); | ||||
This is not a so good idea. Instead of blocking through a nested loop, please use an asynchronous API. mgallien: This is not a so good idea. Instead of blocking through a nested loop, please use an… | |||||
45 | | ||||
46 | return QNetworkReply::NoError == response->error(); | ||||
47 | } | ||||
48 | | ||||
20 | #include "moc_elisautils.cpp" | 49 | #include "moc_elisautils.cpp" |
If this is gonna be used, please use the new connect syntax. There are plenty of examples within Elisa.