2014-12-12 00:00:02 -07:00
|
|
|
/* Copyright (C) 2015 Michael Zimmermann
|
|
|
|
*
|
|
|
|
* 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, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "OperationNamePartition.h"
|
|
|
|
#include "Partition.h"
|
|
|
|
#include "PartitionVector.h"
|
2014-12-12 00:00:02 -07:00
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
OperationNamePartition::OperationNamePartition( const Device & device,
|
|
|
|
const Partition & partition_orig,
|
|
|
|
const Partition & partition_new )
|
|
|
|
{
|
|
|
|
type = OPERATION_NAME_PARTITION;
|
|
|
|
|
2015-05-24 07:13:37 -06:00
|
|
|
this->device = device.get_copy_without_partitions();
|
2015-12-05 09:26:30 -07:00
|
|
|
this->partition_original = partition_orig.clone();
|
|
|
|
this->partition_new = partition_new.clone();
|
2015-09-20 03:50:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
OperationNamePartition::~OperationNamePartition()
|
|
|
|
{
|
|
|
|
delete partition_original;
|
|
|
|
delete partition_new;
|
C++11: Convert NULL to nullptr (!117)
In C++11, nullptr [1] is the strongly typed value to use instead of the
macro NULL [2]. Use everywhere [3][4].
[1] nullptr, the pointer literal (since C++11)
https://en.cppreference.com/w/cpp/language/nullptr
[2] NULL
https://en.cppreference.com/w/cpp/types/NULL
[3] Bjarne Stroustrup's C++ Style and Technique FAQ, Should I use NULL
or 0?
https://www.stroustrup.com/bs_faq2.html#null
"In C++, the definition of NULL is 0, so there is only an
aesthetic difference. I prefer to avoid macros, so I use 0.
Another problem with NULL is that people sometimes mistakenly
believe that it is different from 0 and/or not an integer. In
pre-standard code, NULL was/is sometimes defined to something
unsuitable and therefore had/has to be avoided. That's less
common these days.
If you have to name the null pointer, call it nullptr; that's
what it's called in C++11. Then, "nullptr" will be a keyword.
"
[4] What is nullptr in C++? Advantages, Use Cases & Examples
https://favtutor.com/blogs/nullptr-cpp
"Advantages of nullptr
...
Compatible: Null pointers are compatible with null pointer
constants in the C style (such as NULL and 0). This implies
that old C code that uses these constants and null pointers can
communicate with each other in C++.
"
Closes !117 - Require C++11 compilation
2023-08-31 14:08:59 -06:00
|
|
|
partition_original = nullptr;
|
|
|
|
partition_new = nullptr;
|
2014-12-12 00:00:02 -07:00
|
|
|
}
|
|
|
|
|
2015-05-23 13:22:37 -06:00
|
|
|
void OperationNamePartition::apply_to_visual( PartitionVector & partitions )
|
2014-12-12 00:00:02 -07:00
|
|
|
{
|
2015-09-26 07:25:58 -06:00
|
|
|
substitute_new( partitions );
|
2014-12-12 00:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OperationNamePartition::create_description()
|
|
|
|
{
|
C++11: Convert NULL to nullptr (!117)
In C++11, nullptr [1] is the strongly typed value to use instead of the
macro NULL [2]. Use everywhere [3][4].
[1] nullptr, the pointer literal (since C++11)
https://en.cppreference.com/w/cpp/language/nullptr
[2] NULL
https://en.cppreference.com/w/cpp/types/NULL
[3] Bjarne Stroustrup's C++ Style and Technique FAQ, Should I use NULL
or 0?
https://www.stroustrup.com/bs_faq2.html#null
"In C++, the definition of NULL is 0, so there is only an
aesthetic difference. I prefer to avoid macros, so I use 0.
Another problem with NULL is that people sometimes mistakenly
believe that it is different from 0 and/or not an integer. In
pre-standard code, NULL was/is sometimes defined to something
unsuitable and therefore had/has to be avoided. That's less
common these days.
If you have to name the null pointer, call it nullptr; that's
what it's called in C++11. Then, "nullptr" will be a keyword.
"
[4] What is nullptr in C++? Advantages, Use Cases & Examples
https://favtutor.com/blogs/nullptr-cpp
"Advantages of nullptr
...
Compatible: Null pointers are compatible with null pointer
constants in the C style (such as NULL and 0). This implies
that old C code that uses these constants and null pointers can
communicate with each other in C++.
"
Closes !117 - Require C++11 compilation
2023-08-31 14:08:59 -06:00
|
|
|
g_assert(partition_new != nullptr); // Bug: Not initialised by constructor or reset later
|
2015-09-20 03:50:57 -06:00
|
|
|
|
|
|
|
if( partition_new->name.empty() )
|
2014-12-12 00:00:02 -07:00
|
|
|
{
|
|
|
|
/* TO TRANSLATORS: looks like Clear partition name on /dev/hda3 */
|
2019-03-25 14:41:08 -06:00
|
|
|
description = Glib::ustring::compose( _("Clear partition name on %1"),
|
2015-09-20 03:50:57 -06:00
|
|
|
partition_new->get_path() );
|
2014-12-12 00:00:02 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TO TRANSLATORS: looks like Set partition name "My Name" on /dev/hda3 */
|
2019-03-25 14:41:08 -06:00
|
|
|
description = Glib::ustring::compose( _("Set partition name \"%1\" on %2"),
|
2015-09-20 03:50:57 -06:00
|
|
|
partition_new->name,
|
|
|
|
partition_new->get_path() );
|
2014-12-12 00:00:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 07:59:40 -06:00
|
|
|
bool OperationNamePartition::merge_operations( const Operation & candidate )
|
|
|
|
{
|
C++11: Convert NULL to nullptr (!117)
In C++11, nullptr [1] is the strongly typed value to use instead of the
macro NULL [2]. Use everywhere [3][4].
[1] nullptr, the pointer literal (since C++11)
https://en.cppreference.com/w/cpp/language/nullptr
[2] NULL
https://en.cppreference.com/w/cpp/types/NULL
[3] Bjarne Stroustrup's C++ Style and Technique FAQ, Should I use NULL
or 0?
https://www.stroustrup.com/bs_faq2.html#null
"In C++, the definition of NULL is 0, so there is only an
aesthetic difference. I prefer to avoid macros, so I use 0.
Another problem with NULL is that people sometimes mistakenly
believe that it is different from 0 and/or not an integer. In
pre-standard code, NULL was/is sometimes defined to something
unsuitable and therefore had/has to be avoided. That's less
common these days.
If you have to name the null pointer, call it nullptr; that's
what it's called in C++11. Then, "nullptr" will be a keyword.
"
[4] What is nullptr in C++? Advantages, Use Cases & Examples
https://favtutor.com/blogs/nullptr-cpp
"Advantages of nullptr
...
Compatible: Null pointers are compatible with null pointer
constants in the C style (such as NULL and 0). This implies
that old C code that uses these constants and null pointers can
communicate with each other in C++.
"
Closes !117 - Require C++11 compilation
2023-08-31 14:08:59 -06:00
|
|
|
g_assert(partition_new != nullptr); // Bug: Not initialised by constructor or reset later
|
2015-09-20 03:50:57 -06:00
|
|
|
|
2015-09-19 08:57:39 -06:00
|
|
|
if ( candidate.type == OPERATION_NAME_PARTITION &&
|
2015-09-20 03:50:57 -06:00
|
|
|
*partition_new == candidate.get_partition_original() )
|
2015-09-12 07:59:40 -06:00
|
|
|
{
|
2015-09-20 03:50:57 -06:00
|
|
|
partition_new->name = candidate.get_partition_new().name;
|
2015-09-12 07:59:40 -06:00
|
|
|
create_description();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-12 00:00:02 -07:00
|
|
|
} //GParted
|