@ -26,6 +26,7 @@
@@ -26,6 +26,7 @@
# include "src/historykeeper.h"
# include "src/misc/style.h"
# include "src/profilelocker.h"
# include "src/profile.h"
# include <QLabel>
# include <QLineEdit>
# include <QGroupBox>
@ -35,17 +36,6 @@
@@ -35,17 +36,6 @@
# include <QFileDialog>
# include <QBuffer>
void ProfileForm : : refreshProfiles ( )
{
bodyUI - > profiles - > clear ( ) ;
for ( QString profile : Settings : : getInstance ( ) . searchProfiles ( ) )
bodyUI - > profiles - > addItem ( profile ) ;
QString current = Settings : : getInstance ( ) . getCurrentProfile ( ) ;
if ( current ! = " " )
bodyUI - > profiles - > setCurrentText ( current ) ;
}
ProfileForm : : ProfileForm ( QWidget * parent ) :
QWidget { parent } , qr { nullptr }
{
@ -98,25 +88,12 @@ ProfileForm::ProfileForm(QWidget *parent) :
@@ -98,25 +88,12 @@ ProfileForm::ProfileForm(QWidget *parent) :
connect ( bodyUI - > toxIdLabel , SIGNAL ( clicked ( ) ) , this , SLOT ( copyIdClicked ( ) ) ) ;
connect ( toxId , SIGNAL ( clicked ( ) ) , this , SLOT ( copyIdClicked ( ) ) ) ;
connect ( core , & Core : : idSet , this , & ProfileForm : : setToxId ) ;
connect ( core , & Core : : statusSet , this , & ProfileForm : : onStatusSet ) ;
connect ( bodyUI - > userName , SIGNAL ( editingFinished ( ) ) , this , SLOT ( onUserNameEdited ( ) ) ) ;
connect ( bodyUI - > statusMessage , SIGNAL ( editingFinished ( ) ) , this , SLOT ( onStatusMessageEdited ( ) ) ) ;
connect ( bodyUI - > loadButton , & QPushButton : : clicked , this , & ProfileForm : : onLoadClicked ) ;
connect ( bodyUI - > renameButton , & QPushButton : : clicked , this , & ProfileForm : : onRenameClicked ) ;
connect ( bodyUI - > exportButton , & QPushButton : : clicked , this , & ProfileForm : : onExportClicked ) ;
connect ( bodyUI - > deleteButton , & QPushButton : : clicked , this , & ProfileForm : : onDeleteClicked ) ;
connect ( bodyUI - > importButton , & QPushButton : : clicked , this , & ProfileForm : : onImportClicked ) ;
connect ( bodyUI - > newButton , & QPushButton : : clicked , this , & ProfileForm : : onNewClicked ) ;
connect ( core , & Core : : avStart , this , & ProfileForm : : disableSwitching ) ;
connect ( core , & Core : : avStarting , this , & ProfileForm : : disableSwitching ) ;
connect ( core , & Core : : avInvite , this , & ProfileForm : : disableSwitching ) ;
connect ( core , & Core : : avRinging , this , & ProfileForm : : disableSwitching ) ;
connect ( core , & Core : : avCancel , this , & ProfileForm : : enableSwitching ) ;
connect ( core , & Core : : avEnd , this , & ProfileForm : : enableSwitching ) ;
connect ( core , & Core : : avEnding , this , & ProfileForm : : enableSwitching ) ;
connect ( core , & Core : : avPeerTimeout , this , & ProfileForm : : enableSwitching ) ;
connect ( core , & Core : : avRequestTimeout , this , & ProfileForm : : enableSwitching ) ;
connect ( bodyUI - > logoutButton , & QPushButton : : clicked , this , & ProfileForm : : onLogoutClicked ) ;
connect ( core , & Core : : usernameSet , this , [ = ] ( const QString & val ) { bodyUI - > userName - > setText ( val ) ; } ) ;
connect ( core , & Core : : statusMessageSet , this , [ = ] ( const QString & val ) { bodyUI - > statusMessage - > setText ( val ) ; } ) ;
@ -187,7 +164,6 @@ void ProfileForm::setToxId(const QString& id)
@@ -187,7 +164,6 @@ void ProfileForm::setToxId(const QString& id)
qr = new QRWidget ( ) ;
qr - > setQRData ( " tox: " + id ) ;
bodyUI - > qrCode - > setPixmap ( QPixmap : : fromImage ( qr - > getImage ( ) - > scaledToWidth ( 150 ) ) ) ;
refreshProfiles ( ) ;
}
void ProfileForm : : onAvatarClicked ( )
@ -250,22 +226,9 @@ void ProfileForm::onAvatarClicked()
@@ -250,22 +226,9 @@ void ProfileForm::onAvatarClicked()
Nexus : : getCore ( ) - > setAvatar ( bytes ) ;
}
void ProfileForm : : onLoadClicked ( )
{
if ( bodyUI - > profiles - > currentText ( ) ! = Settings : : getInstance ( ) . getCurrentProfile ( ) )
{
if ( Core : : getInstance ( ) - > anyActiveCalls ( ) )
GUI : : showWarning ( tr ( " Call active " , " popup title " ) ,
tr ( " You can't switch profiles while a call is active! " , " popup text " ) ) ;
else
emit Widget : : getInstance ( ) - > changeProfile ( bodyUI - > profiles - > currentText ( ) ) ;
// I think by directly calling the function, I may have been causing thread issues
}
}
void ProfileForm : : onRenameClicked ( )
{
QString cur = bodyUI - > profiles - > currentText ( ) ;
/** TODO: Create a rename (low level) function in Profile, use it
QString title = tr ( " Rename \" %1 \" " , " renaming a profile " ) . arg ( cur ) ;
do
{
@ -297,11 +260,12 @@ void ProfileForm::onRenameClicked()
@@ -297,11 +260,12 @@ void ProfileForm::onRenameClicked()
break ;
}
} while ( true ) ;
*/
}
void ProfileForm : : onExportClicked ( )
{
QString current = bodyUI - > profiles - > currentText ( ) + Core : : TOX_EXT ;
QString current = Nexus : : getProfile ( ) - > getName ( ) + Core : : TOX_EXT ;
QString path = QFileDialog : : getSaveFileName ( 0 , tr ( " Export profile " , " save dialog title " ) ,
QDir : : home ( ) . filePath ( current ) ,
tr ( " Tox save file (*.tox) " , " save dialog filter " ) ) ;
@ -319,6 +283,7 @@ void ProfileForm::onExportClicked()
@@ -319,6 +283,7 @@ void ProfileForm::onExportClicked()
void ProfileForm : : onDeleteClicked ( )
{
/** Add a delete function in profile
if ( Settings : : getInstance ( ) . getCurrentProfile ( ) = = bodyUI - > profiles - > currentText ( ) )
{
GUI : : showWarning ( tr ( " Profile currently loaded " , " current profile deletion warning title " ) , tr ( " This profile is currently in use. Please load a different profile before deleting this one. " , " current profile deletion warning text " ) ) ;
@ -340,76 +305,22 @@ void ProfileForm::onDeleteClicked()
@@ -340,76 +305,22 @@ void ProfileForm::onDeleteClicked()
bodyUI - > profiles - > setCurrentText ( Settings : : getInstance ( ) . getCurrentProfile ( ) ) ;
}
}
*/
}
void ProfileForm : : onImpor tClicked ( )
void ProfileForm : : onLogou tClicked ( )
{
QString path = QFileDialog : : getOpenFileName ( 0 ,
tr ( " Import profile " , " import dialog title " ) ,
QDir : : homePath ( ) ,
tr ( " Tox save file (*.tox) " , " import dialog filter " ) ) ;
if ( path . isEmpty ( ) )
return ;
QFileInfo info ( path ) ;
QString profile = info . completeBaseName ( ) ;
if ( info . suffix ( ) ! = " tox " )
{
GUI : : showWarning ( tr ( " Ignoring non-Tox file " , " popup title " ) ,
tr ( " Warning: you've chosen a file that is not a Tox save file; ignoring. " , " popup text " ) ) ;
return ;
}
QString profilePath = QDir ( Settings : : getSettingsDirPath ( ) ) . filePath ( profile + Core : : TOX_EXT ) ;
if ( QFileInfo ( profilePath ) . exists ( ) & & ! GUI : : askQuestion ( tr ( " Profile already exists " , " import confirm title " ) ,
tr ( " A profile named \" %1 \" already exists. Do you want to erase it? " , " import confirm text " ) . arg ( profile ) ) )
return ;
QFile : : copy ( path , profilePath ) ;
bodyUI - > profiles - > addItem ( profile ) ;
/// TODO: Save and call Nexus show login?
}
void ProfileForm : : onStatusSet ( Status )
{
refreshProfiles ( ) ;
}
void ProfileForm : : onNewClicked ( )
{
emit Widget : : getInstance ( ) - > changeProfile ( QString ( ) ) ;
}
void ProfileForm : : disableSwitching ( )
{
bodyUI - > loadButton - > setEnabled ( false ) ;
bodyUI - > newButton - > setEnabled ( false ) ;
}
void ProfileForm : : enableSwitching ( )
{
if ( ! core - > anyActiveCalls ( ) )
{
bodyUI - > loadButton - > setEnabled ( true ) ;
bodyUI - > newButton - > setEnabled ( true ) ;
}
}
void ProfileForm : : showEvent ( QShowEvent * event )
{
refreshProfiles ( ) ;
QWidget : : showEvent ( event ) ;
}
void ProfileForm : : on_copyQr_clicked ( )
void ProfileForm : : onCopyQrClicked ( )
{
QApplication : : clipboard ( ) - > setImage ( * qr - > getImage ( ) ) ;
}
void ProfileForm : : on_saveQr_c licked ( )
void ProfileForm : : onSaveQrClicked ( )
{
QString current = bodyUI - > profiles - > currentText ( ) + " .png " ;
QString current = Nexus : : getProfile ( ) - > getName ( ) + " .png " ;
QString path = QFileDialog : : getSaveFileName ( 0 , tr ( " Save " , " save qr image " ) ,
QDir : : home ( ) . filePath ( current ) ,
tr ( " Save QrCode (*.png) " , " save dialog filter " ) ) ;
@ -424,14 +335,3 @@ void ProfileForm::on_saveQr_clicked()
@@ -424,14 +335,3 @@ void ProfileForm::on_saveQr_clicked()
GUI : : showWarning ( tr ( " Failed to copy file " ) , tr ( " The file you chose could not be written to. " ) ) ;
}
}
bool ProfileForm : : eventFilter ( QObject * o , QEvent * e )
{
if ( ( e - > type ( ) = = QEvent : : Wheel ) & &
( qobject_cast < QComboBox * > ( o ) | | qobject_cast < QAbstractSpinBox * > ( o ) ) )
{
e - > ignore ( ) ;
return true ;
}
return QWidget : : eventFilter ( o , e ) ;
}