1 /* === This file is part of Calamares - <https://calamares.io> ===
2 *
3 * SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * Calamares is Free Software: see the License-Identifier above.
7 *
8 */
9
10 #include "DeviceInfoWidget.h"
11
12 #include "GlobalStorage.h"
13 #include "JobQueue.h"
14 #include "utils/CalamaresUtilsGui.h"
15 #include "utils/Logger.h"
16 #include "utils/QtCompat.h"
17 #include "utils/Retranslator.h"
18
19 #include <QDir>
20 #include <QHBoxLayout>
21 #include <QLabel>
22
DeviceInfoWidget(QWidget * parent)23 DeviceInfoWidget::DeviceInfoWidget( QWidget* parent )
24 : QWidget( parent )
25 , m_ptIcon( new QLabel )
26 , m_ptLabel( new QLabel )
27 , m_tableType( PartitionTable::unknownTableType )
28 {
29 QHBoxLayout* mainLayout = new QHBoxLayout;
30 setLayout( mainLayout );
31
32 CalamaresUtils::unmarginLayout( mainLayout );
33 m_ptLabel->setObjectName( "deviceInfoLabel" );
34 m_ptIcon->setObjectName( "deviceInfoIcon" );
35 mainLayout->addWidget( m_ptIcon );
36 mainLayout->addWidget( m_ptLabel );
37
38 QSize iconSize = CalamaresUtils::defaultIconSize();
39
40 m_ptIcon->setMargin( 0 );
41 m_ptIcon->setFixedSize( iconSize );
42 m_ptIcon->setPixmap(
43 CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionTable, CalamaresUtils::Original, iconSize ) );
44
45 QFontMetrics fm = QFontMetrics( QFont() );
46 m_ptLabel->setMinimumWidth( fm.boundingRect( "Amiga" ).width() + CalamaresUtils::defaultFontHeight() / 2 );
47 m_ptLabel->setAlignment( Qt::AlignCenter );
48
49 QPalette palette;
50 palette.setBrush( WindowText, QColor( "#4D4D4D" ) ); //dark grey
51
52 m_ptIcon->setAutoFillBackground( true );
53 m_ptLabel->setAutoFillBackground( true );
54 m_ptIcon->setPalette( palette );
55 m_ptLabel->setPalette( palette );
56
57 CALAMARES_RETRANSLATE_SLOT( &DeviceInfoWidget::retranslateUi );
58 }
59
60
61 void
setPartitionTableType(PartitionTable::TableType type)62 DeviceInfoWidget::setPartitionTableType( PartitionTable::TableType type )
63 {
64 m_tableType = type;
65 retranslateUi();
66 }
67
68 void
retranslateUi()69 DeviceInfoWidget::retranslateUi()
70 {
71 QString typeString = PartitionTable::tableTypeToName( m_tableType ).toUpper();
72
73 // fix up if the name shouldn't be uppercase:
74 switch ( m_tableType )
75 {
76 case PartitionTable::msdos:
77 case PartitionTable::msdos_sectorbased:
78 typeString = "MBR";
79 break;
80 case PartitionTable::loop:
81 typeString = "loop";
82 break;
83 case PartitionTable::mac:
84 typeString = "Mac";
85 break;
86 case PartitionTable::amiga:
87 typeString = "Amiga";
88 break;
89 case PartitionTable::sun:
90 typeString = "Sun";
91 break;
92 case PartitionTable::unknownTableType:
93 typeString = " ? ";
94 }
95
96
97 QString toolTipString = tr( "This device has a <strong>%1</strong> partition "
98 "table." )
99 .arg( typeString );
100
101 switch ( m_tableType )
102 {
103 case PartitionTable::loop:
104 toolTipString = tr( "This is a <strong>loop</strong> "
105 "device.<br><br>"
106 "It is a pseudo-device with no partition table "
107 "that makes a file accessible as a block device. "
108 "This kind of setup usually only contains a single filesystem." );
109 break;
110 case PartitionTable::unknownTableType:
111 toolTipString = tr( "This installer <strong>cannot detect a partition table</strong> on the "
112 "selected storage device.<br><br>"
113 "The device either has no partition "
114 "table, or the partition table is corrupted or of an unknown "
115 "type.<br>"
116 "This installer can create a new partition table for you, "
117 "either automatically, or through the manual partitioning "
118 "page." );
119 break;
120 case PartitionTable::gpt:
121 toolTipString += tr( "<br><br>This is the recommended partition table type for modern "
122 "systems which start from an <strong>EFI</strong> boot "
123 "environment." );
124 break;
125 case PartitionTable::msdos:
126 case PartitionTable::msdos_sectorbased:
127 toolTipString += tr( "<br><br>This partition table type is only advisable on older "
128 "systems which start from a <strong>BIOS</strong> boot "
129 "environment. GPT is recommended in most other cases.<br><br>"
130 "<strong>Warning:</strong> the MBR partition table "
131 "is an obsolete MS-DOS era standard.<br>"
132 "Only 4 <em>primary</em> partitions may be created, and of "
133 "those 4, one can be an <em>extended</em> partition, which "
134 "may in turn contain many <em>logical</em> partitions." );
135 }
136
137 m_ptLabel->setText( typeString );
138 m_ptLabel->setToolTip( toolTipString );
139
140 m_ptIcon->setToolTip( tr( "The type of <strong>partition table</strong> on the "
141 "selected storage device.<br><br>"
142 "The only way to change the partition table type is to "
143 "erase and recreate the partition table from scratch, "
144 "which destroys all data on the storage device.<br>"
145 "This installer will keep the current partition table "
146 "unless you explicitly choose otherwise.<br>"
147 "If unsure, on modern systems GPT is preferred." ) );
148 }
149