File: Select_Icon_Window.cpp

package info (click to toggle)
aqemu 0.7.3-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,112 kB
  • ctags: 1,783
  • sloc: cpp: 26,502; sh: 234; makefile: 37
file content (205 lines) | stat: -rw-r--r-- 5,150 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/****************************************************************************
**
** Copyright (C) 2008-2009 Andrey Rijov <ANDron142@yandex.ru>
**
** This file is part of AQEMU.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA  02110-1301, USA.
**
****************************************************************************/

#include <QFileDialog>
#include <QFileInfoList>
#include <QDir>

#include "Utils.h"
#include "Select_Icon_Window.h"

Select_Icon_Window::Select_Icon_Window( QWidget *parent )
	: QDialog( parent )
{
	ui.setupUi( this );
	
	GB_Locked = false;
	
	ui.GB_Default_Icons->setChecked( false );
	ui.GB_All_Icons->setChecked( false );
	ui.GB_Other_Icons->setChecked( false );
	
	// load all icons
	QDir *icons_dir = new QDir( Settings.value("AQEMU_Data_Folder", "").toString() + "/os_icons/" );
	QFileInfoList icon_files = icons_dir->entryInfoList( QDir::Files, QDir::Name | QDir::IgnoreCase );
	
	for( int ix = 0; ix < icon_files.count(); ++ix )
	{
		QListWidgetItem *ic = new QListWidgetItem( QIcon(icon_files[ix].absoluteFilePath()),
				icon_files[ix].baseName(), ui.All_Icons_List );
		ic->setData( 128, icon_files[ix].absoluteFilePath() );
	}
}

void Select_Icon_Window::Set_Previous_Icon_Path( const QString& path )
{
	// Analise path...
	if( path[0] == ':' ) // AQEMU Default Icons
	{
		ui.GB_Default_Icons->setChecked( true );
		
		if( path.indexOf("linux") > 0 ) ui.RB_Icon_Linux->setChecked( true );
		else if( path.indexOf("windows") > 0 ) ui.RB_Icon_Windows->setChecked( true );
		else ui.RB_Icon_Other->setChecked( true );
	}
	else if( path.indexOf(Settings.value("AQEMU_Data_Folder", "").toString() + "/os_icons/") == 0 ) // AQEMU Icons Folder
	{
		ui.GB_All_Icons->setChecked( true );
		
		QFileInfo fl = QFileInfo( path );
		
		for( int ix = 0; ix < ui.All_Icons_List->count(); ++ix )
		{
			if( ui.All_Icons_List->item(ix)->text() == fl.baseName() )
			{
				ui.All_Icons_List->setCurrentRow( ix );
				ui.All_Icons_List->scrollToItem( ui.All_Icons_List->item(ix),
						QAbstractItemView::PositionAtCenter );
			}
		}
	}
	else
	{
		// Other Path
		ui.GB_Other_Icons->setChecked( true );
		ui.Edit_Other_Icon_Path->setText( path );
	}
}

QString Select_Icon_Window::Get_New_Icon_Path() const
{
	return New_Icon_Path;
}

void Select_Icon_Window::on_Button_OK_clicked()
{
	// Check values
	if( ui.GB_Default_Icons->isChecked() )
	{
		if( ui.RB_Icon_Other->isChecked() )
		{
			New_Icon_Path = ":/images/other.png";
			accept();
		}
		else if( ui.RB_Icon_Windows->isChecked() )
		{
			New_Icon_Path = ":/images/default_windows.png";
			accept();
		}
		else if( ui.RB_Icon_Linux->isChecked() )
		{
			New_Icon_Path = ":/images/default_linux.png";
			accept();
		}
	}
	else if( ui.GB_All_Icons->isChecked() )
	{
		if( ui.All_Icons_List->currentItem() != NULL )
		{
			New_Icon_Path = ui.All_Icons_List->currentItem()->data( 128 ).toString();
			accept();
		}
	}
	else if( ui.GB_Other_Icons->isChecked() )
	{
		if( QFile::exists(ui.Edit_Other_Icon_Path->text()) )
		{
			New_Icon_Path = ui.Edit_Other_Icon_Path->text();
			accept();
		}
		else
		{
			AQGraphic_Warning( tr("Error!"), tr("Icon File Not Exists!") );
		}
	}
}

void Select_Icon_Window::on_Button_Browse_clicked()
{
	QFileDialog::Options options;
	QString selectedFilter;
	
	QString icon_path = QFileDialog::getOpenFileName( this, tr("Select Icon File:"), QDir::homePath(),
													  tr("PNG Images (*.png)"), &selectedFilter, options );
	
	if( icon_path.isEmpty() ) return;
	
	if( ! QFile::exists(icon_path) )
	{
		AQError( "void Select_Icon_Window::on_Button_Browse_clicked()",
				 "File No Exists!" );
	}
	else
	{
		ui.Edit_Other_Icon_Path->setText( icon_path );
	}
}

void Select_Icon_Window::on_GB_Default_Icons_toggled( bool on )
{
	if( ! on ) return;
	
	if( GB_Locked == false )
	{
		GB_Locked = true;
		
		ui.GB_All_Icons->setChecked( ! on );
		ui.GB_Other_Icons->setChecked( ! on );
		
		GB_Locked = false;
	}
}

void Select_Icon_Window::on_GB_All_Icons_toggled( bool on )
{
	if( ! on ) return;
	
	if( GB_Locked == false )
	{
		GB_Locked = true;
		
		ui.GB_Default_Icons->setChecked( ! on );
		ui.GB_Other_Icons->setChecked( ! on );
		
		GB_Locked = false;
	}
}

void Select_Icon_Window::on_GB_Other_Icons_toggled( bool on )
{
	if( ! on ) return;
	
	if( GB_Locked == false )
	{
		GB_Locked = true;
		
		ui.GB_Default_Icons->setChecked( ! on );
		ui.GB_All_Icons->setChecked( ! on );
		
		GB_Locked = false;
	}
}

void Select_Icon_Window::on_All_Icons_List_itemDoubleClicked( QListWidgetItem *item )
{
	on_Button_OK_clicked();
}