<commit_before>/* Copyright (C) 2005-2010, <NAME> <<EMAIL>>
   Copyright (C) 2009, <NAME> <<EMAIL>>

   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   - Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
   - Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
   - Neither the name of the Mumble Developers nor the names of its
     contributors may be used to endorse or promote products derived from this
     software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "MainWindow.h"
#include "AudioWizard.h"
#include "Cert.h"
#include "AudioInput.h"
#include "ConnectDialog.h"
#include "User.h"
#include "Channel.h"
#include "ACLEditor.h"
#include "BanEditor.h"
#include "UserEdit.h"
#include "Tokens.h"
#include "Connection.h"
#include "ServerHandler.h"
#include "About.h"
#include "GlobalShortcut.h"
#include "VersionCheck.h"
#include "UserModel.h"
#include "AudioStats.h"
#include "Plugins.h"
#include "Log.h"
#include "Overlay.h"
#include "Global.h"
#include "Database.h"
#include "ViewCert.h"
#include "TextMessage.h"
#include "NetworkConfig.h"
#include "ACL.h"
#include "UserInformation.h"
#include "VoiceRecorderDialog.h"

#ifdef Q_OS_WIN
#include "TaskList.h"
#endif

#ifdef QT_MAC_USE_COCOA
#include "ConfigDialog_macx.h"
#endif

/*!
  \fn void MainWindow::findDesiredChannel()
  This function tries to join a desired channel on connect. It gets called
  directly after server syncronization is completed.
  \see void MainWindow::msgServerSync(const MumbleProto::ServerSync &msg)
*/

/*!
  \fn void MainWindow::on_qteChat_tabPressed()
  Controlls tab username completion for the chatbar.
  \see ChatbarLineEdit::completeAtCursor()
*/

/*!
  \fn void MainWindow::on_qteChat_ctrlSpacePressed()
  Controlls ctrl space username completion and selection for the chatbar.
  \see ChatbarLineEdit::completeAtCursor()
*/

/*!
  \fn void MainWindow::qtvUserCurrentChanged(const QModelIndex &, const QModelIndex &)
  This function updates the qteChat bar default text according to
  the selected user/channel in the users treeview.
*/

/*!
  \fn void MainWindow::serverConnected()
  This function prepares the UI for receiving server data. It gets called once the
  connection to the server is established but before the server Sync is complete.
*/

/*!
  \fn MainWindow::updateMenuPermissions()
  This function updates the UI according to the permission of the user in the current channel.
  If possible the permissions are fetched from a cache. Otherwise they are requested by the server
  via a PermissionQuery call (whose reply updates the cache and calls this function again).
  \see MainWindow::msgPermissionQuery(const MumbleProto::PermissionQuery &msg)
*/

/*!
  \fn QPair<QByteArray, QImage> MainWindow::openImageFile()
  Presents a file open dialog, opens the selected picture and returns it.
  \return Pair consisting of the raw file contents and the image. Unitialized on error or cancel.
*/

MessageBoxEvent::MessageBoxEvent(QString m) : QEvent(static_cast<QEvent::Type>(MB_QEVENT)) {
	msg = m;
}

OpenURLEvent::OpenURLEvent(QUrl u) : QEvent(static_cast<QEvent::Type>(OU_QEVENT)) {
	url = u;
}

const QString MainWindow::defaultStyleSheet = QLatin1String(".log-channel{text-decoration:none;}.log-user{text-decoration:none;}p{margin:0;}");

MainWindow::MainWindow(QWidget *p) : QMainWindow(p) {
	qiIconMuteSelf.addFile(QLatin1String("skin:muted_self.svg"));
	qiIconMuteServer.addFile(QLatin1String("skin:muted_server.svg"));
	qiIconMuteSuppressed.addFile(QLatin1String("skin:muted_suppressed.svg"));
	qiIconDeafSelf.addFile(QLatin1String("skin:deafened_self.svg"));
	qiIconDeafServer.addFile(QLatin1String("skin:deafened_server.svg"));
	qiTalkingOff.addFile(QLatin1String("skin:talking_off.svg"));
	qiTalkingOn.addFile(QLatin1String("skin:talking_on.svg"));
	qiTalkingShout.addFile(QLatin1String("skin:talking_alt.svg"));
	qiTalkingWhisper.addFile(QLatin1String("skin:talking_whisper.svg"));

#ifdef Q_OS_MAC
	if (QFile::exists(QLatin1String("skin:mumble.icns")))
		qiIcon.addFile(QLatin1String("skin:mumble.icns"));
	else
		qiIcon.addFile(QLatin1String("skin:mumble.svg"));
#else
	qiIcon.addFile(QLatin1String("skin:mumble.svg"));
	// Set application icon except on MacOSX, where the window-icon
	// shown in the title-bar usually serves as a draggable version of the
	// current open document (i.e. you can copy the open document anywhere
	// simply by dragging this icon).
	qApp->setWindowIcon(qiIcon);
#endif

#ifdef Q_OS_WIN
	uiNewHardware = 1;
#endif
	bSuppressAskOnQuit = false;
	bAutoUnmute = false;

	Channel::add(0, tr("Root"));

	aclEdit = NULL;
	banEdit = NULL;
	userEdit = NULL;
	tokenEdit = NULL;

	voiceRecorderDialog = NULL;

	uiContextSession = ~0;
	iContextChannel = -1;

	qtReconnect = new QTimer(this);
	qtReconnect->setInterval(10000);
	qtReconnect->setSingleShot(true);
	qtReconnect->setObjectName(QLatin1String("Reconnect"));<commit_msg>Alternative svg rendering for application icon<commit_after>/* Copyright (C) 2005-2010, <NAME> <<EMAIL>>
   Copyright (C) 2009, <NAME> <<EMAIL>>

   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   - Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
   - Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
   - Neither the name of the Mumble Developers nor the names of its
     contributors may be used to endorse or promote products derived from this
     software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "MainWindow.h"
#include "AudioWizard.h"
#include "Cert.h"
#include "AudioInput.h"
#include "ConnectDialog.h"
#include "User.h"
#include "Channel.h"
#include "ACLEditor.h"
#include "BanEditor.h"
#include "UserEdit.h"
#include "Tokens.h"
#include "Connection.h"
#include "ServerHandler.h"
#include "About.h"
#include "GlobalShortcut.h"
#include "VersionCheck.h"
#include "UserModel.h"
#include "AudioStats.h"
#include "Plugins.h"
#include "Log.h"
#include "Overlay.h"
#include "Global.h"
#include "Database.h"
#include "ViewCert.h"
#include "TextMessage.h"
#include "NetworkConfig.h"
#include "ACL.h"
#include "UserInformation.h"
#include "VoiceRecorderDialog.h"

#ifdef Q_OS_WIN
#include "TaskList.h"
#endif

#ifdef QT_MAC_USE_COCOA
#include "ConfigDialog_macx.h"
#endif

/*!
  \fn void MainWindow::findDesiredChannel()
  This function tries to join a desired channel on connect. It gets called
  directly after server syncronization is completed.
  \see void MainWindow::msgServerSync(const MumbleProto::ServerSync &msg)
*/

/*!
  \fn void MainWindow::on_qteChat_tabPressed()
  Controlls tab username completion for the chatbar.
  \see ChatbarLineEdit::completeAtCursor()
*/

/*!
  \fn void MainWindow::on_qteChat_ctrlSpacePressed()
  Controlls ctrl space username completion and selection for the chatbar.
  \see ChatbarLineEdit::completeAtCursor()
*/

/*!
  \fn void MainWindow::qtvUserCurrentChanged(const QModelIndex &, const QModelIndex &)
  This function updates the qteChat bar default text according to
  the selected user/channel in the users treeview.
*/

/*!
  \fn void MainWindow::serverConnected()
  This function prepares the UI for receiving server data. It gets called once the
  connection to the server is established but before the server Sync is complete.
*/

/*!
  \fn MainWindow::updateMenuPermissions()
  This function updates the UI according to the permission of the user in the current channel.
  If possible the permissions are fetched from a cache. Otherwise they are requested by the server
  via a PermissionQuery call (whose reply updates the cache and calls this function again).
  \see MainWindow::msgPermissionQuery(const MumbleProto::PermissionQuery &msg)
*/

/*!
  \fn QPair<QByteArray, QImage> MainWindow::openImageFile()
  Presents a file open dialog, opens the selected picture and returns it.
  \return Pair consisting of the raw file contents and the image. Unitialized on error or cancel.
*/

MessageBoxEvent::MessageBoxEvent(QString m) : QEvent(static_cast<QEvent::Type>(MB_QEVENT)) {
	msg = m;
}

OpenURLEvent::OpenURLEvent(QUrl u) : QEvent(static_cast<QEvent::Type>(OU_QEVENT)) {
	url = u;
}

const QString MainWindow::defaultStyleSheet = QLatin1String(".log-channel{text-decoration:none;}.log-user{text-decoration:none;}p{margin:0;}");

MainWindow::MainWindow(QWidget *p) : QMainWindow(p) {
	qiIconMuteSelf.addFile(QLatin1String("skin:muted_self.svg"));
	qiIconMuteServer.addFile(QLatin1String("skin:muted_server.svg"));
	qiIconMuteSuppressed.addFile(QLatin1String("skin:muted_suppressed.svg"));
	qiIconDeafSelf.addFile(QLatin1String("skin:deafened_self.svg"));
	qiIconDeafServer.addFile(QLatin1String("skin:deafened_server.svg"));
	qiTalkingOff.addFile(QLatin1String("skin:talking_off.svg"));
	qiTalkingOn.addFile(QLatin1String("skin:talking_on.svg"));
	qiTalkingShout.addFile(QLatin1String("skin:talking_alt.svg"));
	qiTalkingWhisper.addFile(QLatin1String("skin:talking_whisper.svg"));

#ifdef Q_OS_MAC
	if (QFile::exists(QLatin1String("skin:mumble.icns")))
		qiIcon.addFile(QLatin1String("skin:mumble.icns"));
	else
		qiIcon.addFile(QLatin1String("skin:mumble.svg"));
#else
	{
		QSvgRenderer svg(QLatin1String("skin:mumble.svg"));
		QPixmap original(512,512);
		original.fill(Qt::transparent);

		QPainter painter(&original);
		painter.setRenderHint(QPainter::Antialiasing);
		painter.setRenderHint(QPainter::TextAntialiasing);
		painter.setRenderHint(QPainter::SmoothPixmapTransform);
		painter.setRenderHint(QPainter::HighQualityAntialiasing);
		svg.render(&painter);
	
		for(int sz=8;sz<=256;sz+=8)
			qiIcon.addPixmap(original.scaled(sz,sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
	}

	// Set application icon except on MacOSX, where the window-icon
	// shown in the title-bar usually serves as a draggable version of the
	// current open document (i.e. you can copy the open document anywhere
	// simply by dragging this icon).
	qApp->setWindowIcon(qiIcon);
#endif

#ifdef Q_OS_WIN
	uiNewHardware = 1;
#endif
	bSuppressAskOnQuit = false;
	bAutoUnmute = false;

	Channel::add(0, tr("Root"));

	aclEdit = NULL;
	banEdit = NULL;
	userEdit = NULL;
	tokenEdit = NULL;

	voiceRecorderDialog = NULL;

	uiContextSession = ~0;
	iContextChannel = -1;

	qtReconnect = new QTimer(this);
	qtReconnect->setInterval(10000);
	qtReconnect->setSingleShot(true);
	qtReconnect->setObjectName(QLatin1String("Reconnect"));
{'fraction_non_alphanumeric': 0.10020661157024793, 'fraction_numerical': 0.0067546090273363, 'mean_word_length': 5.346444780635401, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5417400', 'n_tokens_mistral': 4079, 'n_tokens_neox': 3861, 'n_words': 1200}