File indexing completed on 2024-04-14 04:50:21

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "choqoktools.h"
0010 #include "choqokuiglobal.h"
0011 
0012 #include <QDesktopServices>
0013 
0014 #include <KProcess>
0015 #include <KMessageBox>
0016 
0017 #include "choqokbehaviorsettings.h"
0018 
0019 void Choqok::openUrl(const QUrl &url)
0020 {
0021     bool urlOpeningFailed = false;
0022     QString failureMessage;
0023     if (Choqok::BehaviorSettings::useCustomBrowser()) {
0024         QStringList args = Choqok::BehaviorSettings::customBrowser().split(QLatin1Char(' '));
0025         args.append(url.toString());
0026         if (KProcess::startDetached(args) == 0) {
0027             urlOpeningFailed = true;
0028             failureMessage = i18n("Custom web browser \"%1\" is unable to open url \"%2\".\nPlease update the custom web browser in Configurations.",
0029                                  Choqok::BehaviorSettings::customBrowser(), url.toDisplayString());
0030         }
0031     } else if(!QDesktopServices::openUrl(url)) {
0032         urlOpeningFailed = true;
0033         failureMessage = i18n("Unable to open url \"%1\".\nPlease check Qt installation or set a custom web browser in Configurations.",
0034                               url.toDisplayString());
0035     }
0036     
0037     if (urlOpeningFailed)
0038         KMessageBox::error(Choqok::UI::Global::mainWindow(), failureMessage);
0039 }
0040 
0041 QString Choqok::getColorString(const QColor &color)
0042 {
0043     return QLatin1String("rgb(") + QString::number(color.red()) + QLatin1Char(',') + QString::number(color.green()) + QLatin1Char(',') +
0044            QString::number(color.blue()) + QLatin1Char(')');
0045 }