summaryrefslogblamecommitdiffstats
path: root/src/gui/profileDialog.cpp
blob: 9f7e8a578f689d561dfa04f992d94762083675d3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                                                
 

                                                
 
                      
 


                                                               
 


                                                                       



                               

 
                         
 

                      

 
                            
 





                                                                     

 
                          
 
                           
         







                                                                                                         
         


                                                                                                   
         


                                                        
         


                                                       

 
                          
 

                                                             
 

                                                                                                   
                          


                                                        









                                                                  


                                                 
 
/*
 # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
 #
 # This program is free software distributed under the GPL version 2.
 # See http://openslx.org/COPYING
 #
 # If you have any feedback please consult http://openslx.org/feedback and
 # send your suggestions, praise, or complaints to feedback@openslx.org
 #
 # General information about OpenSLX can be found at http://openslx.org/
 # -----------------------------------------------------------------------------
 # profileDialog.cpp
 #    - GUI to define the profile.
 # -----------------------------------------------------------------------------
 */

#include "profileDialog.h"

profileDialog::profileDialog(QWidget * parent) :
	QDialog(parent)
{
	setupUi(this);

	_profiles = new QSettings("openslx", "profiles", this);
	_current = _profiles->value("current").toString();
	listWidget->addItems(_profiles->childGroups());

	connect(addButton, SIGNAL(clicked()), this, SLOT(add()));
	connect(loadButton, SIGNAL(clicked()), this, SLOT(load()));
	connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
}

profileDialog::~profileDialog()
{
}

void profileDialog::add()
{
	_current = "";
	save();
}

void profileDialog::remove()
{
	if (listWidget->currentItem())
	{
		_profiles->remove(listWidget->currentItem()->text());
		listWidget->clear();
		listWidget->addItems(_profiles->childGroups());
	}
}

void profileDialog::save()
{
	if (_current == "")
	{
		QString profile = QInputDialog::getText(this, tr("New Profile"), tr("Save profile as:"));
    	if (!profile.isEmpty())
    	{
    		_current = profile;
    		_profiles->setValue("current", _current);
    	}
    	else
    		return;
	}
	QList<ConnectionFrame*> clients = MainWindow::getConnectionWindow()->getAllFrameOnWindow();
	_profiles->beginGroup(_current);
	foreach (ConnectionFrame *client, clients)
	{
		QString key = client->getTaskbarTitle();
		QPoint value = client->pos();
		_profiles->setValue(key, value);
	}
	_profiles->endGroup();
    listWidget->clear();
	listWidget->addItems(_profiles->childGroups());
}

void profileDialog::load()
{
	if (listWidget->currentItem())
		_current = listWidget->currentItem()->text();

	QList<ConnectionFrame*> clients = MainWindow::getConnectionWindow()->getAllFrameOnWindow();
	_profiles->beginGroup(_current);
	QPoint shift(0,0);
	foreach (ConnectionFrame *client, clients)
	{
		QString key = client->getTaskbarTitle();
		QPoint position = _profiles->value(key).toPoint();
		if (position != QPoint(0,0))
		    client->move(position);
		else
		{
		    client->move(shift);
		    shift += QPoint(10,10);
		}


	}
	_profiles->endGroup();
	_profiles->setValue("current", _current);
}