Refactor code for displaying device name with alias

This commit is contained in:
Tony George 2014-11-24 22:52:53 +05:30
parent ef778674de
commit 42aa52b631
4 changed files with 214 additions and 224 deletions

View File

@ -837,13 +837,7 @@ public class Main : GLib.Object{
foreach(Device pi in partition_list) {
if (!pi.has_linux_filesystem()) { continue; }
//log_msg("%4d > %-15s %s %10s %s".printf(++index, pi.device, pi.uuid, (pi.size_mb > 0) ? "%0.0f GB".printf(pi.size_mb / 1024.0) : "", pi.label));
string symlink = "";
foreach(string sym in pi.symlinks){
if (sym.has_prefix("/dev/mapper/")){
symlink = sym;
}
}
log_msg("%4d > %s%s %s %s %s %s".printf(++index, pi.device, (symlink.length > 0) ? "" + symlink : "" , pi.uuid, (pi.size_mb > 0) ? "%0.0fGB".printf(pi.size_mb / 1024.0) : "", pi.type, pi.label));
log_msg("%4d > %s %s %s %s %s".printf(++index, pi.short_name_with_alias, pi.uuid, (pi.size_mb > 0) ? "%0.0fGB".printf(pi.size_mb / 1024.0) : "", pi.type, pi.label));
}
}
@ -2081,7 +2075,7 @@ public class Main : GLib.Object{
//print target device name
log_msg(TERM_COLOR_YELLOW + string.nfill(78, '*') + TERM_COLOR_RESET);
log_msg(_("Target Device") + ": %s".printf(restore_target.device + ((symlink.length > 0) ? "" + symlink : "")), true);
log_msg(_("Target Device") + ": %s".printf(restore_target.full_name_with_alias), true);
log_msg(TERM_COLOR_YELLOW + string.nfill(78, '*') + TERM_COLOR_RESET);
}
else{
@ -2136,7 +2130,7 @@ public class Main : GLib.Object{
log_msg(_("'%s' will be on root device").printf(mnt.mount_point), true);
}
else{
log_msg(_("'%s' will be on '%s'").printf(mnt.mount_point, mnt.device.device), true);
log_msg(_("'%s' will be on '%s'").printf(mnt.mount_point, mnt.device.short_name_with_alias), true);
}
log_msg(TERM_COLOR_YELLOW + string.nfill(78, '*') + TERM_COLOR_RESET);
}

View File

@ -850,15 +850,8 @@ public class RestoreWindow : Gtk.Dialog{
if (!pi.has_linux_filesystem()) { continue; }
if (!radio_sys.sensitive && (App.root_device != null) && ((pi.device == App.root_device.device)||(pi.uuid == App.root_device.uuid))) { continue; }
string symlink = "";
foreach(string sym in pi.symlinks){
if (sym.has_prefix("/dev/mapper/")){
symlink = sym;
}
}
string tt = "";
tt += "%-7s".printf(_("Device")) + "\t: %s\n".printf(pi.device + ((symlink.length > 0) ? "" + symlink : ""));
tt += "%-7s".printf(_("Device")) + "\t: %s\n".printf(pi.full_name_with_alias);
tt += "%-7s".printf(_("UUID")) + "\t: %s\n".printf(pi.uuid);
tt += "%-7s".printf(_("Type")) + "\t: %s\n".printf(pi.type);
tt += "%-7s".printf(_("Label")) + "\t: %s\n".printf(pi.label);
@ -1424,19 +1417,12 @@ public class RestoreWindow : Gtk.Dialog{
private int show_mount_list(){
string msg = _("Following mounts will be used for restored system:") + "\n\n";
int max_mount = _("Mount").length;
int max_dev = _("Device").length;
foreach(MountEntry mnt in App.mount_list){
string symlink = "";
foreach(string sym in mnt.device.symlinks){
if (sym.has_prefix("/dev/mapper/")){
symlink = sym.replace("/dev/mapper/","");
}
}
string dev_name = mnt.device.device.replace("/dev/","") + ((symlink.length > 0) ? " (" + symlink + ")" : "");//
string dev_name = mnt.device.short_name_with_alias;
if (dev_name.length > max_dev){ max_dev = dev_name.length; }
if (mnt.mount_point.length > max_mount){ max_mount = mnt.mount_point.length; }
}
@ -1446,14 +1432,7 @@ public class RestoreWindow : Gtk.Dialog{
msg += ("%%-%ds %%-%ds\n\n".printf(max_dev, max_mount)).printf(_("Device"),_("Mount"));
msg += "</b>";
foreach(MountEntry mnt in App.mount_list){
string symlink = "";
foreach(string sym in mnt.device.symlinks){
if (sym.has_prefix("/dev/mapper/")){
symlink = sym.replace("/dev/mapper/","");
}
}
msg += ("%%-%ds %%-%ds\n\n".printf(max_dev, max_mount)).printf(mnt.device.device.replace("/dev/","") + ((symlink.length > 0) ? " (" + symlink + ")" : ""), mnt.mount_point);
msg += ("%%-%ds %%-%ds\n\n".printf(max_dev, max_mount)).printf(mnt.device.short_name_with_alias, mnt.mount_point);
}
msg += "</tt>";
msg += "\n" + _("Click OK to continue") + "\n";

View File

@ -486,11 +486,36 @@ namespace TeeJee.Devices{
return udev_device.get_name();
}
else{
return device.replace("/dev/","").replace("/dev/mapper/","");
return device.replace("/dev/mapper/","").replace("/dev/","");
}
}
}
public string full_name_with_alias{
owned get{
string fullname = "";
string symlink = "";
foreach(string sym in symlinks){
if (sym.has_prefix("/dev/mapper/")){
symlink = sym;
}
}
fullname = device + ((symlink.length > 0) ? " (" + symlink + ")" : ""); //
if (devtype == "partition"){
return fullname;
}
else{
return name;
}
}
}
public string short_name_with_alias{
owned get{
return full_name_with_alias.replace("/dev/mapper/","").replace("/dev/","");
}
}
public void print_properties(){
if (udev_device != null){
foreach(string key in udev_device.get_property_keys()){
@ -507,19 +532,11 @@ namespace TeeJee.Devices{
string s = "";
if (devtype == "disk"){
s += "<b>" + device.replace("/dev/","") + "</b>";
s += "<b>" + short_name_with_alias + "</b>";
s += ((vendor.length > 0)||(model.length > 0)) ? (" ~ " + vendor + " " + model) : "";
}
else{
string symlink = "";
foreach(string sym in symlinks){
if (sym.has_prefix("/dev/mapper/")){
symlink = sym.replace("/dev/mapper/","");
}
}
s += "<b>" + device.replace("/dev/","") + ((symlink.length > 0) ? "" + symlink : "") + "</b>" ;
s += "<b>" + short_name_with_alias + "</b>" ;
s += (label.length > 0) ? " (" + label + ")": "";
s += (type.length > 0) ? " ~ " + type : "";
s += (used.length > 0) ? " ~ " + used + " / " + size + " GB used (" + used_percent + ")" : "";

File diff suppressed because it is too large Load Diff