File: Select_Icon_Window.cpp

package info (click to toggle)
aqemu 0.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 5,740 kB
  • ctags: 2,347
  • sloc: cpp: 31,857; makefile: 2
file content (149 lines) | stat: -rw-r--r-- 4,295 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
/****************************************************************************
**
** Copyright (C) 2008-2010 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 );
	
	// load all icons
	QDir *icons_dir = new QDir( QDir::toNativeSeparators(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
	{
		if( path.contains("linux", Qt::CaseInsensitive) ) ui.RB_Icon_Linux->setChecked( true );
		else if( path.contains("windows", Qt::CaseInsensitive) ) ui.RB_Icon_Windows->setChecked( true );
		else ui.RB_Icon_Other->setChecked( true );
	}
	else if( path.indexOf(QDir::toNativeSeparators(Settings.value("AQEMU_Data_Folder", "").toString() + "/os_icons/")) == 0 ) // AQEMU Icons Folder
	{
		ui.RB_All_System_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 );
				
				// This hack :)
				ui.All_Icons_List->setViewMode( QListView::ListMode );
				ui.All_Icons_List->setViewMode( QListView::IconMode );
				return;
			}
		}
	}
	else // Other Path
	{
		ui.RB_User_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.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.RB_All_System_Icons->isChecked() )
	{
		if( ui.All_Icons_List->currentItem() != NULL )
		{
			New_Icon_Path = ui.All_Icons_List->currentItem()->data( 128 ).toString();
			accept();
		}
	}
	else if( ui.RB_User_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 doesn't exist!") );
		}
	}
}

void Select_Icon_Window::on_Button_Browse_clicked()
{
	QString iconPath = QFileDialog::getOpenFileName( this, tr("Select Icon File:"),
													 Get_Last_Dir_Path(ui.Edit_Other_Icon_Path->text()),
													 tr("PNG Images (*.png)") );
	
	if( iconPath.isEmpty() ) return;
	iconPath = QDir::toNativeSeparators( iconPath );

	if( ! QFile::exists(iconPath) )
	{
		AQError( "void Select_Icon_Window::on_Button_Browse_clicked()",
				 "File No Exists!" );
	}
	else
	{
		ui.Edit_Other_Icon_Path->setText( iconPath );
	}
}

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