diff --git a/src/mumble/ConnectDialog.cpp b/src/mumble/ConnectDialog.cpp index e124b484f..8f1817f11 100644 --- a/src/mumble/ConnectDialog.cpp +++ b/src/mumble/ConnectDialog.cpp @@ -364,7 +364,7 @@ ServerItem::~ServerItem() { delete si; } -ServerItem *ServerItem::fromMimeData(const QMimeData *mime, QWidget *p) { +ServerItem *ServerItem::fromMimeData(const QMimeData *mime, bool default_name, QWidget *p) { if (mime->hasFormat(QLatin1String("OriginatedInMumble"))) return NULL; @@ -413,7 +413,7 @@ ServerItem *ServerItem::fromMimeData(const QMimeData *mime, QWidget *p) { } #if QT_VERSION >= 0x050000 - if (! query.hasQueryItem(QLatin1String("title"))) + if (! query.hasQueryItem(QLatin1String("title")) && default_name) query.addQueryItem(QLatin1String("title"), url.host()); ServerItem *si = new ServerItem(query.queryItemValue(QLatin1String("title")), url.host(), static_cast(url.port(DEFAULT_MUMBLE_PORT)), url.userName(), url.password()); @@ -421,7 +421,7 @@ ServerItem *ServerItem::fromMimeData(const QMimeData *mime, QWidget *p) { if (query.hasQueryItem(QLatin1String("url"))) si->qsUrl = query.queryItemValue(QLatin1String("url")); #else - if (! url.hasQueryItem(QLatin1String("title"))) + if (! url.hasQueryItem(QLatin1String("title")) && default_name) url.addQueryItem(QLatin1String("title"), url.host()); ServerItem *si = new ServerItem(url.queryItemValue(QLatin1String("title")), url.host(), static_cast(url.port(DEFAULT_MUMBLE_PORT)), url.userName(), url.password()); @@ -1017,7 +1017,7 @@ void ConnectDialog::on_qaFavoriteAddNew_triggered() { // Try to fill out fields if possible { - ServerItem *si = ServerItem::fromMimeData(QApplication::clipboard()->mimeData()); + ServerItem *si = ServerItem::fromMimeData(QApplication::clipboard()->mimeData(), false); if (si) { // If there is server information in the clipboard assume user wants to add it name = si->qsName; diff --git a/src/mumble/ConnectDialog.h b/src/mumble/ConnectDialog.h index 3cbb05daa..daad98ae9 100644 --- a/src/mumble/ConnectDialog.h +++ b/src/mumble/ConnectDialog.h @@ -166,7 +166,23 @@ class ServerItem : public QTreeWidgetItem, public PingStats { ServerItem(const QString &name, ItemType itype, const QString &continent = QString(), const QString &country = QString()); ServerItem(const ServerItem *si); ~ServerItem(); - static ServerItem *fromMimeData(const QMimeData *mime, QWidget *p = NULL); + + /// Converts given mime data into a ServerItem object + /// + /// This function checks the clipboard for a valid mumble:// style + /// URL and converts it into a ServerItem ready to add to the connect + /// dialog. It also parses .lnk files of InternetShortcut/URL type + /// to enable those to be dropped onto the clipboard. + /// + /// @note If needed can query the user for a user name using a modal dialog. + /// @note If a server item is returned it's the callers reponsibility to delete it. + /// + /// @param mime Mime data to analyze + /// @param default_name If true the hostname is set as item name if none is given + /// @param p Parent widget to use in case the user has to be queried + /// @return Server item or NULL if mime data invalid. + /// + static ServerItem *fromMimeData(const QMimeData *mime, bool default_name = true, QWidget *p = NULL); void addServerItem(ServerItem *child); @@ -201,7 +217,13 @@ class ConnectDialogEdit : public QDialog, protected Ui::ConnectDialogEdit { public: QString qsName, qsHostname, qsUsername, qsPassword; unsigned short usPort; - ConnectDialogEdit(QWidget *parent, const QString &name = QString(), const QString &host = QString(), const QString &user = QString(), unsigned short port = DEFAULT_MUMBLE_PORT, const QString &password = QString(), bool add = false); + ConnectDialogEdit(QWidget *parent, + const QString &name = QString(), + const QString &host = QString(), + const QString &user = QString(), + unsigned short port = DEFAULT_MUMBLE_PORT, + const QString &password = QString(), + bool add = false); }; class ConnectDialog : public QDialog, public Ui::ConnectDialog {