Author: aschnell
Date: Fri Jun 27 17:58:55 2008
New Revision: 48669
URL: http://svn.opensuse.org/viewcvs/yast?rev=48669&view=rev
Log:
- backup commit
Modified:
branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc
branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h
branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h
branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc
branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp
branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc?rev=48669&r1=48668&r2=48669&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc Fri Jun 27 17:58:55 2008
@@ -16,6 +16,7 @@
#include <fstream>
#include <sstream>
#include <iostream>
+#include
#include
@@ -6381,28 +6382,53 @@
}
-string Storage::byteToHumanString(unsigned long long size, int precision, bool omit_zeroes) const
+static int numSuffixes()
{
- const char* prefixes[] = {
- /* Byte abbreviated */
- _("B"),
- /* KiloByte abbreviated */
- _("kB"),
- /* MegaByte abbreviated */
- _("MB"),
- /* GigaByte abbreviated */
- _("GB"),
- /* TeraByte abbreviated */
- _("TB")
- };
+ return 5;
+}
+
+
+static string suffixes(int i, bool classic)
+{
+ switch (i)
+ {
+ case 0:
+ /* Byte abbreviated */
+ return classic ? "B" : _("B");
+
+ case 1:
+ /* KiloByte abbreviated */
+ return classic ? "kB" : _("kB");
+
+ case 2:
+ /* MegaByte abbreviated */
+ return classic ? "MB" : _("MB");
+
+ case 3:
+ /* GigaByte abbreviated */
+ return classic ? "GB" : _("GB");
+
+ case 4:
+ /* TeraByte abbreviated */
+ return classic ? "TB" : _("TB");
+ }
+
+ return string("error");
+}
+
+
+string Storage::byteToHumanString(unsigned long long size, bool classic, int precision,
+ bool omit_zeroes) const
+{
+ const locale loc = locale::classic();
double f = (double)(size);
- unsigned int prefix = 0;
+ int suffix = 0;
- while (f >= 1024.0 && prefix + 1 < lengthof(prefixes))
+ while (f >= 1024.0 && suffix + 1 < numSuffixes())
{
f /= 1024.0;
- prefix++;
+ suffix++;
}
if (omit_zeroes && (f == (unsigned long long)(f)))
@@ -6411,13 +6437,47 @@
}
ostringstream s;
+ s.imbue(loc);
s.setf(ios::fixed);
s.precision(precision);
- s << f << ' ' << prefixes[prefix];
+
+ s << f << ' ' << suffixes(suffix, classic);
+
return s.str();
}
+bool Storage::humanStringToByte(const string& str, bool classic, unsigned long long& size) const
+{
+ const locale loc = locale::classic();
+
+ istringstream s(boost::trim_copy(str, loc));
+ s.imbue(loc);
+
+ double f;
+ string suffix;
+ s >> f >> suffix;
+
+ if (s.fail() || !s.eof() || f < 0.0)
+ return false;
+
+ boost::to_lower(suffix, loc);
+
+ for(int i = 0; i < numSuffixes(); i++)
+ {
+ if (suffix == boost::to_lower_copy(suffixes(i, classic)))
+ {
+ size = f;
+ return true;
+ }
+
+ f *= 1024.0;
+ }
+
+ return false;
+}
+
+
namespace storage
{
std::ostream& operator<< (std::ostream& s, Storage &v )
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h?rev=48669&r1=48668&r2=48669&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h Fri Jun 27 17:58:55 2008
@@ -470,8 +470,9 @@
void updateDmEmptyPeMap();
void dumpObjectList();
- string byteToHumanString(unsigned long long size, int precision, bool omit_zeroes) const;
-
+ string byteToHumanString(unsigned long long size, bool classic, int precision, bool omit_zeroes) const;
+ bool humanStringToByte(const string& str, bool classic, unsigned long long& size) const;
+
void setCallbackProgressBar( storage::CallbackProgressBar pfnc )
{ progress_bar_cb=pfnc; }
storage::CallbackProgressBar getCallbackProgressBar() const
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h?rev=48669&r1=48668&r2=48669&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h Fri Jun 27 17:58:55 2008
@@ -2170,17 +2170,33 @@
* and using B, kB, MB, GB or TB as unit as appropriate.
*
* @param size size in bytes
+ * @param classic use classic locale
* @param precision number of fraction digits in output
* @param omit_zeroes if true omit trailing zeroes for exact values
* @return formatted string
*
- * @example byteToHumanString(128, 2, true) -> "128 B"
- * @example byteToHumanString(4096, 2, true) -> "4 kB"
- * @example byteToHumanString(4096, 2, false) -> "4.00 kB"
- * @example byteToHumanString(1024*1024, 2, true) -> "1 MB"
+ * @example byteToHumanString(128, true, 2, true) -> "128 B"
+ * @example byteToHumanString(4096, true, 2, true) -> "4 kB"
+ * @example byteToHumanString(4096, true, 2, false) -> "4.00 kB"
+ * @example byteToHumanString(1024*1024, true, 2, true) -> "1 MB"
*/
- virtual string byteToHumanString(unsigned long long size, int precision,
+ virtual string byteToHumanString(unsigned long long size, bool classic, int precision,
bool omit_zeroes) const = 0;
+
+ /**
+ * Converts a size description using B, kB, MB, GB or TB into an integer.
+ *
+ * @param str size string
+ * @param classic use classic locale
+ * @param size size in bytes
+ * @return true on successful conversion
+ *
+ * @example humanStringToByte("4kB", true, size) -> true and size = 4*1024
+ * @example humanStringToByte("4 MB", true, size) -> true and size = 4*1024*1024
+ * @example humanStringToByte("0.5 GB", true, size) -> true and size = 512*1024*1024
+ */
+ virtual bool humanStringToByte(const string& str, bool classic, unsigned long long&
+ size) const = 0;
};
Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc?rev=48669&r1=48668&r2=48669&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc (original)
+++ branches/tmp/aschnell/part-redesign/libstorage/src/Volume.cc Fri Jun 27 17:58:55 2008
@@ -2558,7 +2558,7 @@
string Volume::sizeString() const
{
- return cont->getStorage()->byteToHumanString(1024 * size_k, 2, false);
+ return cont->getStorage()->byteToHumanString(1024 * size_k, false, 2, false);
}
bool Volume::canUseDevice() const
Modified: branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp?rev=48669&r1=48668&r2=48669&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/include/ep-dialogs.ycp Fri Jun 27 17:58:55 2008
@@ -80,7 +80,11 @@
{
// TODO
string s = (string) UI::QueryWidget(`id(`size_input), `Value);
- integer i = Storage::KmgtStrToByte(s);
+
+ integer i = 0;
+ Storage::HumanStringToByte(s, i);
+ // integer i = Storage::KmgtStrToByte(s);
+
integer num_cyl = tointeger(float::ceil(tofloat(i) / tofloat(data["cyl_size"]:42)));
data["region"] = [ slot[0]:0, num_cyl ];
break;
@@ -113,6 +117,9 @@
string tmp = Storage::ByteToHumanString(max_size);
+ symbol what = `max_size;
+ integer manual_size = 0;
+
frames = add(frames,
`Frame(_("Size"),
`RadioButtonGroup(`id(`size),
@@ -172,7 +179,19 @@
break;
case `next:
- // TODO: checks
+ what = (symbol) UI::QueryWidget(`id(`size), `Value);
+ if (what == `manual_size)
+ {
+ string s = (string) UI::QueryWidget(`id(`size_input), `Value);
+ if (!Storage::HumanStringToByte(s, manual_size))
+ {
+ Error(_("The size in invalid. TODO"));
+ widget = `again;
+ }
+ }
+
+ // TODO min-size check
+
stripes = (integer) UI::QueryWidget(`id(`stripes), `Value);
stripe_size = (integer) UI::QueryWidget(`id(`stripe_size), `Value);
break;
@@ -182,16 +201,14 @@
if (widget == `next)
{
- switch ((symbol) UI::QueryWidget(`id(`size), `Value))
+ switch (what)
{
case `max_size:
data["size_k"] = max_size / 1024;
break;
case `manual_size:
- string s = (string) UI::QueryWidget(`id(`size_input), `Value);
- integer i = Storage::KmgtStrToByte(s);
- data["size_k"] = i / 1024;
+ data["size_k"] = manual_size / 1024;
break;
}
Modified: branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp?rev=48669&r1=48668&r2=48669&view=diff
==============================================================================
--- branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp (original)
+++ branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp Fri Jun 27 17:58:55 2008
@@ -322,13 +322,21 @@
global string ByteToHumanString(integer bytes)
{
- return LibStorage::StorageInterface::byteToHumanString(sint, bytes, 2, false);
+ return LibStorage::StorageInterface::byteToHumanString(sint, bytes, false, 2, false);
}
global string ByteToHumanStringWithPrecision(integer bytes, integer precision, boolean omit_zeroes)
{
- return LibStorage::StorageInterface::byteToHumanString(sint, bytes, precision, omit_zeroes);
+ return LibStorage::StorageInterface::byteToHumanString(sint, bytes, false, precision, omit_zeroes);
+}
+
+
+global boolean HumanStringToByte(string str, integer& bytes)
+{
+ boolean ret = LibStorage::StorageInterface::humanStringToByte(sint, str, false, bytes);
+ y2milestone("HumanStringToByte ret:%1 str:%2 bytes:%3", ret, str, bytes);
+ return ret;
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org