コミットメタ情報

リビジョンa03cd312d994b5340e41e6658ca884d01b69c7b3 (tree)
日時2010-11-13 03:28:33
作者satofumi
コミッターsatofumi

ログメッセージ

充電済みのときに描画しないオプションを追加

変更サマリ

差分

diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/BatmonWidget.cpp
--- a/qlm_batmon/BatmonWidget.cpp Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/BatmonWidget.cpp Fri Nov 12 18:28:33 2010 +0000
@@ -27,369 +27,472 @@
2727
2828 namespace
2929 {
30- const char* Organization = "Hyakuren Soft LTD.";
31- const char* Application = "qlm_batmon";
30+ const char* Organization = "Hyakuren Soft LTD.";
31+ const char* Application = "qlm_batmon";
3232 };
3333
3434
3535 struct BatmonWidget::pImpl
3636 {
37- enum {
38- IntervalMsec = 2000, // [msec]
39- };
40-
41- BatmonWidget* widget_;
42- BatteryState battery_;
43- ChargingState battery_state_;
44- ChargingState previous_battery_state_;
45- size_t percent_;
46- size_t previous_percent_;
47- QTimer update_timer_;
48- vector<character_t> characters_;
49- size_t character_index_;
50- DrawCharacter draw_character_;
51- QPoint drag_position_;
52-
53- bool hide_checked_;
54- QAction* hide_action_;
55- vector<QAction*> skin_actions_;
56- bool is_masked_;
57-
58- bool is_tray_available_;
59- QSystemTrayIcon tray_icon_;
60-
61-
62- pImpl(BatmonWidget* widget)
63- : widget_(widget),
64- battery_state_(Unknown), previous_battery_state_(Unknown),
65- percent_(0), previous_percent_(0), character_index_(0),
66- hide_checked_(false), hide_action_(NULL), is_masked_(false),
67- is_tray_available_(QSystemTrayIcon::isSystemTrayAvailable())
68- {
69- }
70-
71-
72- void initialize(void)
73- {
74- // アイコンを適用
75- widget_->setWindowIcon(QIcon(":icons/qlm_batmon_icon"));
76-
77- // 背景を灰色にし、アンチエイリアスの効果を期待して少しだけ透明にする
78- QColor color(128, 128, 128, 223);
79- widget_->setPalette(color);
80-
81- update();
82-
83- // 更新用のタイマーを初期化
84- update_timer_.setInterval(IntervalMsec);
85- connect(&update_timer_, SIGNAL(timeout()), widget_, SLOT(updateTimeout()));
86- update_timer_.start();
87- }
88-
37+ enum {
38+ IntervalMsec = 2000, // [msec]
39+ };
8940
90- void initializeCharacters(void)
91- {
92- // 女の子
93- character_t girl;
94- girl.name = tr("girl");
95- girl.picture_unknown = ":picture/girl_unknown";
96- girl.picture_charging = ":picture/girl_charging";
97- girl.picture_discharging = ":picture/girl_discharging";
98- girl.percent_bar = ":picture/percent_bar";
99- girl.bar_position = QPoint(4, 43);
100- characters_.push_back(girl);
101-
102- // りもペンギン
103- character_t penguin;
104- penguin.name = tr("pengui");
105- penguin.picture_unknown = ":picture/penguin_unknown";
106- penguin.picture_charging = ":picture/penguin_charging";
107- penguin.picture_discharging = ":picture/penguin_discharging";
108- penguin.percent_bar = ":picture/percent_bar";
109- penguin.bar_position = QPoint(5, 44);
110- characters_.push_back(penguin);
111- }
112-
41+ BatmonWidget* widget_;
42+ BatteryState battery_;
43+ ChargingState battery_state_;
44+ ChargingState previous_battery_state_;
45+ size_t percent_;
46+ size_t previous_percent_;
47+ QTimer update_timer_;
48+ vector<character_t> characters_;
49+ size_t character_index_;
50+ DrawCharacter draw_character_;
51+ QPoint drag_position_;
11352
114- void initializeMenu(void)
115- {
116- // キャラクタ選択メニューの作成
117- size_t n = characters_.size();
118- for (size_t i = 0; i < n; ++i) {
119- QAction* action = new QAction(characters_[i].name, widget_);
120- action->setCheckable(true);
121- widget_->addAction(action);
122- skin_actions_.push_back(action);
123- }
124- connect(skin_actions_[0], SIGNAL(triggered()),
125- widget_, SLOT(girlSkinSelected()));
126- connect(skin_actions_[1], SIGNAL(triggered()),
127- widget_, SLOT(limoSkinSelected()));
128- setSkin(character_index_);
129-
130- widget_->addAction(newSeparator());
131-
132- // 充電中に非表示にするかのチェックボックス
133- hide_action_ = new QAction(tr("Hide while charging"), widget_);
134- hide_action_->setCheckable(true);
135- hide_action_->setChecked(hide_checked_);
136- widget_->addAction(hide_action_);
137- connect(hide_action_, SIGNAL(triggered()), widget_, SLOT(hideSpecified()));
53+ bool show_always_checked_;
54+ bool hide_charging_checked_;
55+ bool hide_charged_checked_;
13856
139- widget_->addAction(newSeparator());
140-
141- // 終了
142- QAction* quit_action = new QAction(QAction::tr("Quit"), widget_);
143- quit_action->setShortcut(tr("Ctrl+Q"));
144- connect(quit_action, SIGNAL(triggered()), qApp, SLOT(quit()));
145- widget_->addAction(quit_action);
146-
147- widget_->setContextMenuPolicy(Qt::ActionsContextMenu);
148- }
149-
57+ QAction* show_always_action_;
58+ QAction* hide_charging_action_;
59+ QAction* hide_charged_action_;
60+ vector<QAction*> skin_actions_;
61+ bool is_masked_;
15062
151- void initializeSystemTray(void)
152- {
153- // システムトレイにアイコンを配置
154- tray_icon_.setIcon(widget_->windowIcon());
155- tray_icon_.setToolTip(tr("APM Battery Monitor"));
156-
157- QMenu* menu = new QMenu(widget_);
158- QList<QAction*> actions = widget_->actions();
159- for (int i = 0; i < actions.size(); ++i) {
160- menu->addAction(actions.at(i));
161- }
162- tray_icon_.setContextMenu(menu);
163- tray_icon_.hide();
164- }
63+ bool is_tray_available_;
64+ QSystemTrayIcon tray_icon_;
16565
16666
167- QAction* newSeparator(void)
168- {
169- QAction* separator = new QAction(widget_);
170- separator->setSeparator(true);
171- return separator;
172- }
173-
174-
175- void loadSettings(bool restore_geometry)
176- {
177- QSettings settings(Organization, Application);
178-
179- character_index_ = settings.value("character_index", 0).toInt();
180- hide_checked_ = settings.value("hide_checked", false).toBool();
181-
182- if (restore_geometry) {
183- widget_->restoreGeometry(settings.value("geometry").toByteArray());
67+ pImpl(BatmonWidget* widget)
68+ : widget_(widget),
69+ battery_state_(Unknown), previous_battery_state_(Unknown),
70+ percent_(0), previous_percent_(0), character_index_(0),
71+ show_always_checked_(true), hide_charging_checked_(false),
72+ hide_charged_checked_(false),
73+ show_always_action_(NULL), hide_charging_action_(NULL),
74+ hide_charged_action_(NULL), is_masked_(false),
75+ is_tray_available_(QSystemTrayIcon::isSystemTrayAvailable())
76+ {
18477 }
185- }
186-
187-
188- void saveSettings(void)
189- {
190- QSettings settings(Organization, Application);
191-
192- settings.setValue("geometry", widget_->saveGeometry());
193- settings.setValue("character_index", character_index_);
194- settings.setValue("hide_checked", hide_action_->isChecked());
195- }
196-
197-
198- ChargingState batteryState(void)
199- {
200- if (! battery_.isAvailable()) {
201- return Unknown;
202- }
203- return (battery_.isCharging() ? Charging : Discharging);
204- }
20578
20679
207- void update(void)
208- {
209- // 描画する状態の取得
210- battery_state_ = batteryState();
211- percent_ = battery_.remainingPercent();
80+ void initialize(void)
81+ {
82+ // アイコンを適用
83+ widget_->setWindowIcon(QIcon(":icons/qlm_batmon_icon"));
21284
213- // フォーカス時に表示する情報の更新
214- QString message = updateMessage();
215- widget_->setToolTip(message);
85+ // メニュー項目を作成
86+ show_always_action_ = new QAction(tr("Show always"), widget_);
87+ hide_charging_action_ = new QAction(tr("Hide while charging"), widget_);
88+ hide_charged_action_ = new QAction(tr("Hide while charged"), widget_);
89+ connect(show_always_action_, SIGNAL(triggered()),
90+ widget_, SLOT(showAlwaysSpecified()));
91+ connect(hide_charging_action_, SIGNAL(triggered()),
92+ widget_, SLOT(hideChargingSpecified()));
93+ connect(hide_charged_action_, SIGNAL(triggered()),
94+ widget_, SLOT(hideChargedSpecified()));
21695
217- bool repainted = false;
218- if ((battery_state_ != previous_battery_state_) ||
219- percent_ != previous_percent_) {
220- repainted = true;
221- widget_->repaint();
96+ // 背景を灰色にし、アンチエイリアスの効果を期待して少しだけ透明にする
97+ QColor color(128, 128, 128, 223);
98+ widget_->setPalette(color);
99+
100+ update();
101+
102+ // 更新用のタイマーを初期化
103+ update_timer_.setInterval(IntervalMsec);
104+ connect(&update_timer_, SIGNAL(timeout()), widget_, SLOT(updateTimeout()));
105+ update_timer_.start();
222106 }
223- previous_battery_state_ = battery_state_;
224- previous_percent_ = percent_;
225-
226- if (hide_checked_ && (battery_state_ == Charging)) {
227- // 充電中に描画しないよう指定されているときは隠す
228- widget_->hide();
229- if (is_tray_available_) {
230- tray_icon_.show();
231- }
232- } else {
233- if ((! repainted) && widget_->isHidden()) {
234- widget_->show();
235- if (is_tray_available_) {
236- tray_icon_.hide();
237- }
238- }
239- }
240- }
241107
242108
243- // マスコットの再描画
244- void repaint(void)
245- {
246- // 再描画
247- QPainter painter(widget_);
248- QRect base_rect;
249- QRegion region;
250- if (draw_character_.draw(painter, base_rect, region,
251- characters_[character_index_],
252- battery_state_, percent_)) {
253- widget_->resize(base_rect.width(), base_rect.height());
254- if (is_masked_) {
255- widget_->clearMask();
256- }
257- widget_->setMask(region);
258- is_masked_ = true;
109+ void initializeCharacters(void)
110+ {
111+ // 女の子
112+ character_t girl;
113+ girl.name = tr("girl");
114+ girl.picture_unknown = ":picture/girl_unknown";
115+ girl.picture_charging = ":picture/girl_charging";
116+ girl.picture_discharging = ":picture/girl_discharging";
117+ girl.percent_bar = ":picture/percent_bar";
118+ girl.bar_position = QPoint(4, 43);
119+ characters_.push_back(girl);
120+
121+ // りもペンギン
122+ character_t penguin;
123+ penguin.name = tr("pengui");
124+ penguin.picture_unknown = ":picture/penguin_unknown";
125+ penguin.picture_charging = ":picture/penguin_charging";
126+ penguin.picture_discharging = ":picture/penguin_discharging";
127+ penguin.percent_bar = ":picture/percent_bar";
128+ penguin.bar_position = QPoint(5, 44);
129+ characters_.push_back(penguin);
259130 }
260- }
261-
262-
263- double remainingTime(size_t total_second)
264- {
265- return total_second / (60.0 * 60.0);
266- }
267131
268132
269- QString updateMessage(void)
270- {
271- double remaining_time = remainingTime(battery_.remainingSecond());
272- if (remaining_time > 1.0) {
273- remaining_time = floor(remaining_time);
133+ void initializeMenu(void)
134+ {
135+ // キャラクタ選択メニューの作成
136+ size_t n = characters_.size();
137+ for (size_t i = 0; i < n; ++i) {
138+ QAction* action = new QAction(characters_[i].name, widget_);
139+ action->setCheckable(true);
140+ widget_->addAction(action);
141+ skin_actions_.push_back(action);
142+ }
143+ connect(skin_actions_[0], SIGNAL(triggered()),
144+ widget_, SLOT(girlSkinSelected()));
145+ connect(skin_actions_[1], SIGNAL(triggered()),
146+ widget_, SLOT(limoSkinSelected()));
147+ setSkin(character_index_);
148+
149+ widget_->addAction(newSeparator());
150+
151+ // 常に表示させるためのチェックボックス
152+ show_always_action_->setCheckable(true);
153+ show_always_action_->setChecked(show_always_checked_);
154+ widget_->addAction(show_always_action_);
155+
156+ // 充電中に非表示にするかのチェックボックス
157+ hide_charging_action_->setCheckable(true);
158+ hide_charging_action_->setChecked(hide_charging_checked_);
159+ widget_->addAction(hide_charging_action_);
160+
161+ // 充電されるまで表示するかのチェックボックス
162+ hide_charged_action_->setCheckable(true);
163+ hide_charged_action_->setChecked(hide_charged_checked_);
164+ widget_->addAction(hide_charged_action_);
165+
166+ widget_->addAction(newSeparator());
167+
168+ // 終了
169+ QAction* quit_action = new QAction(QAction::tr("Quit"), widget_);
170+ quit_action->setShortcut(tr("Ctrl+Q"));
171+ connect(quit_action, SIGNAL(triggered()), qApp, SLOT(quit()));
172+ widget_->addAction(quit_action);
173+
174+ widget_->setContextMenuPolicy(Qt::ActionsContextMenu);
274175 }
275176
276- switch (battery_state_) {
277- case Charging:
278- return QString(tr("charging: %1 [%]")).arg(percent_);
279- break;
280177
281- case Discharging:
282- if (remaining_time == 0.0) {
283- return QString(tr("remaining: %1 [%]")).arg(percent_);
284- } else {
285- return QString(tr("remaining: %1 [h] (%2 [%])")).arg(remaining_time, 0, 'g', 1).arg(percent_);
286- }
287- break;
178+ void initializeSystemTray(void)
179+ {
180+ // システムトレイにアイコンを配置
181+ tray_icon_.setIcon(widget_->windowIcon());
182+ tray_icon_.setToolTip(tr("APM Battery Monitor"));
288183
289- default:
290- case Unknown:
291- return QString(tr("unknown system"));
292- break;
184+ QMenu* menu = new QMenu(widget_);
185+ QList<QAction*> actions = widget_->actions();
186+ for (int i = 0; i < actions.size(); ++i) {
187+ menu->addAction(actions.at(i));
188+ }
189+ tray_icon_.setContextMenu(menu);
190+ tray_icon_.hide();
293191 }
294- }
295192
296193
297- void setSkin(size_t index)
298- {
299- character_index_ = index;
194+ QAction* newSeparator(void)
195+ {
196+ QAction* separator = new QAction(widget_);
197+ separator->setSeparator(true);
198+ return separator;
199+ }
300200
301- size_t n = skin_actions_.size();
302- for (size_t i = 0; i < n; ++i) {
303- bool checked = (i == index) ? true : false;
304- skin_actions_[i]->setChecked(checked);
201+
202+ void loadSettings(bool restore_geometry)
203+ {
204+ QSettings settings(Organization, Application);
205+
206+ character_index_ = settings.value("character_index", 0).toInt();
207+ show_always_checked_ =
208+ settings.value("show_always_checked", false).toBool();
209+ if (show_always_checked_) {
210+ show_always_action_->setChecked(true);
211+ }
212+
213+ hide_charging_checked_ =
214+ settings.value("hide_charging_checked", false).toBool();
215+ if (hide_charging_checked_) {
216+ hide_charging_action_->setChecked(true);
217+ }
218+
219+ hide_charged_checked_ =
220+ settings.value("hide_charged_checked", false).toBool();
221+ if (hide_charged_checked_) {
222+ hide_charged_action_->setChecked(true);
223+ }
224+
225+ if (restore_geometry) {
226+ widget_->restoreGeometry(settings.value("geometry").toByteArray());
227+ }
305228 }
306- }
229+
230+
231+ void saveSettings(void)
232+ {
233+ QSettings settings(Organization, Application);
234+
235+ settings.setValue("geometry", widget_->saveGeometry());
236+ settings.setValue("character_index", character_index_);
237+ settings.setValue("show_always_checked",
238+ show_always_action_->isChecked());
239+ settings.setValue("hide_charging_checked",
240+ hide_charging_action_->isChecked());
241+ settings.setValue("hide_charged_checked",
242+ hide_charged_action_->isChecked());
243+ }
244+
245+
246+ ChargingState batteryState(void)
247+ {
248+ if (!battery_.isAvailable()) {
249+ return Unknown;
250+ }
251+ if (battery_.isCharged()) {
252+ return Charged;
253+ }
254+ return (battery_.isCharging() ? Charging : Discharging);
255+ }
256+
257+
258+ void update(void)
259+ {
260+ // 描画する状態の取得
261+ battery_state_ = batteryState();
262+ percent_ = battery_.remainingPercent();
263+
264+ // フォーカス時に表示する情報の更新
265+ QString message = updateMessage();
266+ widget_->setToolTip(message);
267+
268+ bool repainted = false;
269+ if ((battery_state_ != previous_battery_state_) ||
270+ percent_ != previous_percent_) {
271+ repainted = true;
272+ widget_->repaint();
273+ }
274+ previous_battery_state_ = battery_state_;
275+ previous_percent_ = percent_;
276+
277+ if (hide_charging_checked_ &&
278+ ((battery_state_ == Charging) || (battery_state_ == Charged))) {
279+ // 充電中に描画しないよう指定されているときは隠す
280+ hideCharacter();
281+
282+ } else if (hide_charged_checked_ && (battery_state_ == Charged)) {
283+ // 充電済みで描画しないよう指定されているときは隠す
284+ hideCharacter();
285+
286+ } else {
287+ if ((!repainted) && widget_->isHidden()) {
288+ widget_->show();
289+ if (is_tray_available_) {
290+ tray_icon_.hide();
291+ }
292+ }
293+ }
294+ }
295+
296+
297+ void hideCharacter(void)
298+ {
299+ widget_->hide();
300+ if (is_tray_available_) {
301+ tray_icon_.show();
302+ }
303+ }
304+
305+
306+ // マスコットの再描画
307+ void repaint(void)
308+ {
309+ // 再描画
310+ QPainter painter(widget_);
311+ QRect base_rect;
312+ QRegion region;
313+ if (draw_character_.draw(painter, base_rect, region,
314+ characters_[character_index_],
315+ battery_state_, percent_)) {
316+ widget_->resize(base_rect.width(), base_rect.height());
317+ if (is_masked_) {
318+ widget_->clearMask();
319+ }
320+ widget_->setMask(region);
321+ is_masked_ = true;
322+ }
323+ }
324+
325+
326+ double remainingTime(size_t total_second)
327+ {
328+ return total_second / (60.0 * 60.0);
329+ }
330+
331+
332+ QString updateMessage(void)
333+ {
334+ double remaining_time = remainingTime(battery_.remainingSecond());
335+ if (remaining_time > 1.0) {
336+ remaining_time = floor(remaining_time);
337+ }
338+
339+ switch (battery_state_) {
340+ case Charging:
341+ return QString(tr("charging: %1 [%]")).arg(percent_);
342+ break;
343+
344+ case Charged:
345+ return QString(tr("charged"));
346+ break;
347+
348+ case Discharging:
349+ if (remaining_time == 0.0) {
350+ return QString(tr("remaining: %1 [%]")).arg(percent_);
351+ } else {
352+ return QString(tr("remaining: %1 [h] (%2 [%])")).
353+ arg(remaining_time, 0, 'g', 1).arg(percent_);
354+ }
355+ break;
356+
357+ default:
358+ case Unknown:
359+ return QString(tr("unknown system"));
360+ break;
361+ }
362+ }
363+
364+
365+ void setSkin(size_t index)
366+ {
367+ character_index_ = index;
368+
369+ size_t n = skin_actions_.size();
370+ for (size_t i = 0; i < n; ++i) {
371+ bool checked = (i == index) ? true : false;
372+ skin_actions_[i]->setChecked(checked);
373+ }
374+ }
375+
376+
377+ void clearChecked(void)
378+ {
379+ show_always_action_->setChecked(false);
380+ hide_charging_action_->setChecked(false);
381+ hide_charged_action_->setChecked(false);
382+
383+ hide_charged_checked_ = false;
384+ show_always_checked_ = false;
385+ hide_charging_checked_ = false;
386+ }
307387 };
308388
309389
310390 BatmonWidget::BatmonWidget(bool geometry_specified, QWidget* widget)
311- : QWidget(widget), pimpl(new pImpl(this))
391+ : QWidget(widget), pimpl(new pImpl(this))
312392 {
313- pimpl->initialize();
314- pimpl->loadSettings(! geometry_specified);
315- pimpl->initializeCharacters();
316- pimpl->initializeMenu();
317- if (pimpl->is_tray_available_) {
318- // システムトレイが利用可能ならば登録
319- pimpl->initializeSystemTray();
320- }
393+ pimpl->initialize();
394+ pimpl->loadSettings(!geometry_specified);
395+ pimpl->initializeCharacters();
396+ pimpl->initializeMenu();
397+ if (pimpl->is_tray_available_) {
398+ // システムトレイが利用可能ならば登録
399+ pimpl->initializeSystemTray();
400+ }
321401
322- if (geometry_specified) {
323- // 位置がコマンドラインで指定され直したため、それを保存する
324- pimpl->saveSettings();
325- }
402+ if (geometry_specified) {
403+ // 位置がコマンドラインで指定され直したため、それを保存する
404+ pimpl->saveSettings();
405+ }
326406 }
327407
328408
329409 BatmonWidget::~BatmonWidget(void)
330410 {
331- pimpl->saveSettings();
411+ pimpl->saveSettings();
332412 }
333413
334414
335415 void BatmonWidget::paintEvent(QPaintEvent* event)
336416 {
337- static_cast<void>(event);
417+ static_cast<void>(event);
338418
339- pimpl->repaint();
419+ pimpl->repaint();
340420 }
341421
342422
343423 void BatmonWidget::updateTimeout(void)
344424 {
345- pimpl->update();
425+ pimpl->update();
346426 }
347427
348428
349429 // 左クリックでのフォーム移動
350430 void BatmonWidget::mousePressEvent(QMouseEvent* event)
351431 {
352- if (event->button() == Qt::LeftButton) {
353- pimpl->drag_position_ = event->globalPos() - frameGeometry().topLeft();
354- event->accept();
355- }
432+ if (event->button() == Qt::LeftButton) {
433+ pimpl->drag_position_ = event->globalPos() - frameGeometry().topLeft();
434+ event->accept();
435+ }
356436 }
357437
358438
359439 // 左クリックでのフォーム移動
360440 void BatmonWidget::mouseMoveEvent(QMouseEvent* event)
361441 {
362- if (event->buttons() & Qt::LeftButton) {
363- move(event->globalPos() - pimpl->drag_position_);
364- pimpl->saveSettings();
365- event->accept();
366- }
442+ if (event->buttons() & Qt::LeftButton) {
443+ move(event->globalPos() - pimpl->drag_position_);
444+ pimpl->saveSettings();
445+ event->accept();
446+ }
367447 }
368448
369449
370-void BatmonWidget::hideSpecified(void)
450+void BatmonWidget::showAlwaysSpecified(void)
371451 {
372- bool check = pimpl->hide_action_->isChecked();
373- pimpl->hide_action_->setChecked(check);
452+ pimpl->clearChecked();
374453
375- pimpl->hide_checked_ = check;
376- pimpl->saveSettings();
454+ pimpl->show_always_action_->setChecked(true);
455+ pimpl->show_always_checked_ = true;
456+
457+ pimpl->saveSettings();
458+}
459+
460+
461+void BatmonWidget::hideChargingSpecified(void)
462+{
463+ pimpl->clearChecked();
464+
465+ pimpl->hide_charging_action_->setChecked(true);
466+ pimpl->hide_charging_checked_ = true;
467+
468+ pimpl->saveSettings();
469+}
470+
471+
472+void BatmonWidget::hideChargedSpecified(void)
473+{
474+ pimpl->clearChecked();
475+
476+ pimpl->hide_charged_action_->setChecked(true);
477+ pimpl->hide_charged_checked_ = true;
478+
479+ pimpl->saveSettings();
377480 }
378481
379482
380483 void BatmonWidget::girlSkinSelected(void)
381484 {
382- pimpl->setSkin(0);
383- update();
384- repaint();
385- pimpl->saveSettings();
485+ pimpl->setSkin(0);
486+ update();
487+ repaint();
488+ pimpl->saveSettings();
386489 }
387490
388491
389492 void BatmonWidget::limoSkinSelected(void)
390493 {
391- pimpl->setSkin(1);
392- update();
393- repaint();
394- pimpl->saveSettings();
494+ pimpl->setSkin(1);
495+ update();
496+ repaint();
497+ pimpl->saveSettings();
395498 }
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/BatmonWidget.h
--- a/qlm_batmon/BatmonWidget.h Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/BatmonWidget.h Fri Nov 12 18:28:33 2010 +0000
@@ -18,29 +18,31 @@
1818 //! バッテリーモニター Widget
1919 class BatmonWidget : public QWidget
2020 {
21- Q_OBJECT;
21+ Q_OBJECT;
2222
2323 public:
24- //! コンストラクタ
25- explicit BatmonWidget(bool geometry_specified, QWidget* widget = NULL);
26- ~BatmonWidget(void);
24+ //! コンストラクタ
25+ explicit BatmonWidget(bool geometry_specified, QWidget* widget = NULL);
26+ ~BatmonWidget(void);
2727
2828 private slots:
29- void paintEvent(QPaintEvent* event);
30- void updateTimeout(void);
31- void hideSpecified(void);
32- void girlSkinSelected(void);
33- void limoSkinSelected(void);
29+ void paintEvent(QPaintEvent* event);
30+ void updateTimeout(void);
31+ void showAlwaysSpecified(void);
32+ void hideChargingSpecified(void);
33+ void hideChargedSpecified(void);
34+ void girlSkinSelected(void);
35+ void limoSkinSelected(void);
3436
3537 private:
36- void mousePressEvent(QMouseEvent* event);
37- void mouseMoveEvent(QMouseEvent* event);
38+ void mousePressEvent(QMouseEvent* event);
39+ void mouseMoveEvent(QMouseEvent* event);
3840
39- BatmonWidget(const BatmonWidget& rhs);
40- BatmonWidget& operator = (const BatmonWidget& rhs);
41+ BatmonWidget(const BatmonWidget& rhs);
42+ BatmonWidget& operator = (const BatmonWidget& rhs);
4143
42- struct pImpl;
43- std::auto_ptr<pImpl> pimpl;
44+ struct pImpl;
45+ std::auto_ptr<pImpl> pimpl;
4446 };
4547
4648 #endif /* !BATMON_WIDGET_H */
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/BatteryState.cpp
--- a/qlm_batmon/BatteryState.cpp Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/BatteryState.cpp Fri Nov 12 18:28:33 2010 +0000
@@ -25,197 +25,221 @@
2525 #if defined(WINDOWS_OS)
2626 struct BatteryState::pImpl
2727 {
28- bool isAvailable(void)
29- {
30- SYSTEM_POWER_STATUS status;
31- if (! GetSystemPowerStatus(&status)) {
32- return false;
28+ bool isAvailable(void)
29+ {
30+ SYSTEM_POWER_STATUS status;
31+ if (!GetSystemPowerStatus(&status)) {
32+ return false;
33+ }
34+ return (status.BatteryLifePercent == 255) ? false : true;
3335 }
34- return (status.BatteryLifePercent == 255) ? false : true;
35- }
3636
3737
38- bool isCharging(void)
39- {
40- SYSTEM_POWER_STATUS status;
41- if (! GetSystemPowerStatus(&status)) {
42- return false;
38+ bool isCharging(void)
39+ {
40+ SYSTEM_POWER_STATUS status;
41+ if (!GetSystemPowerStatus(&status)) {
42+ return false;
43+ }
44+ return (static_cast<int>(status.ACLineStatus) == 1) ? true : false;
4345 }
44- return (static_cast<int>(status.ACLineStatus) == 1) ? true : false;
45- }
4646
4747
48- size_t remainingPercent(void)
49- {
50- SYSTEM_POWER_STATUS status;
51- if (! GetSystemPowerStatus(&status)) {
52- return 0;
48+ bool isCharged(void) const
49+ {
50+ return !isCharging();
5351 }
54- return status.BatteryLifePercent;
55- }
5652
5753
58- size_t remainingSecond(void)
59- {
60- SYSTEM_POWER_STATUS status;
61- if (! GetSystemPowerStatus(&status)) {
62- return 0;
54+ size_t remainingPercent(void)
55+ {
56+ SYSTEM_POWER_STATUS status;
57+ if (!GetSystemPowerStatus(&status)) {
58+ return 0;
59+ }
60+ return status.BatteryLifePercent;
6361 }
64- return max(0, static_cast<int>(status.BatteryLifeTime));
65- }
62+
63+
64+ size_t remainingSecond(void)
65+ {
66+ SYSTEM_POWER_STATUS status;
67+ if (!GetSystemPowerStatus(&status)) {
68+ return 0;
69+ }
70+ return max(0, static_cast<int>(status.BatteryLifeTime));
71+ }
6672 };
6773 #else
6874
6975 struct BatteryState::pImpl
7076 {
71- bool is_available_;
72- size_t full_capacity_;
73- string state_file_;
74- string info_file_;
75-
76-
77- pImpl(void) : is_available_(false), full_capacity_(1)
78- {
79- // BAT0, BAT1 を順番に試す
80- for (size_t id = 0; id < 2; ++id) {
81- char buffer[] = "BAT0";
82- snprintf(buffer, sizeof(buffer), "BAT%d", id);
83-
84- state_file_ = "/proc/acpi/battery/" + string(buffer) + "/state";
85- info_file_ = "/proc/acpi/battery/" + string(buffer) + "/info";
86-
87- if (loadFullCapacity()) {
88- break;
89- }
90- }
91- }
77+ bool is_available_;
78+ size_t full_capacity_;
79+ string state_file_;
80+ string info_file_;
9281
9382
94- bool matchData(string& value, const char* file, const char* pattern) const
95- {
96- ifstream fin(file);
97- if (! fin.is_open()) {
98- return false;
99- }
83+ pImpl(void) : is_available_(false), full_capacity_(1)
84+ {
85+ // BAT0, BAT1 を順番に試す
86+ for (size_t id = 0; id < 2; ++id) {
87+ char buffer[] = "BAT0";
88+ snprintf(buffer, sizeof(buffer), "BAT%d", id);
10089
101- // トークンの区切りを ':' とし、得られた結果からは空白を除去して返す
102- string line;
103- while (getline(fin, line)) {
104- vector<string> tokens;
105- if (split(tokens, line, ":") >= 2) {
106- if (! tokens[0].compare(pattern)) {
107- string& token = tokens[1];
108- size_t first_index = 0;
109- while (token[first_index] == ' ') {
110- ++first_index;
111- }
112- value = &token[first_index];
113- return true;
90+ state_file_ = "/proc/acpi/battery/" + string(buffer) + "/state";
91+ info_file_ = "/proc/acpi/battery/" + string(buffer) + "/info";
92+
93+ if (loadFullCapacity()) {
94+ break;
95+ }
11496 }
115- }
116- }
117- return false;
118- }
119-
120-
121- bool matchData(size_t& value, const char* file, const char* pattern) const
122- {
123- string string_value;
124- if (! matchData(string_value, file, pattern)) {
125- return false;
126- }
127-
128- value = atoi(string_value.c_str());
129- return true;
130- }
131-
132-
133- bool loadFullCapacity(void)
134- {
135- // /proc/acpi/battery/BATx/info ファイルの "last full capacity" を読み出す
136- if ((matchData(full_capacity_, info_file_.c_str(), "last full capacity")) &&
137- (full_capacity_ > 0)) {
138- is_available_ = true;
139- return true;
14097 }
14198
142- return false;
143- }
144-
145-
146- bool isAvailable(void) const
147- {
148- return is_available_;
149- }
150-
151-
152- bool isCharging(void) const
153- {
154- if (! is_available_) {
155- return false;
156- }
15799
158- // 電源が接続されていないときに false を返す
159- // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す
160- string state;
161- if (matchData(state, state_file_.c_str(), "charging state") &&
162- ((! state.compare("charged")) || (! state.compare("charging")))) {
163- return true;
164- }
100+ bool matchData(string& value, const char* file, const char* pattern) const
101+ {
102+ ifstream fin(file);
103+ if (!fin.is_open()) {
104+ return false;
105+ }
165106
166- return false;
167- }
168-
169-
170- size_t remainingPercent(void) const
171- {
172- if (! is_available_) {
173- return 0;
107+ // トークンの区切りを ':' とし、得られた結果からは空白を除去して返す
108+ string line;
109+ while (getline(fin, line)) {
110+ vector<string> tokens;
111+ if (split(tokens, line, ":") >= 2) {
112+ if (!tokens[0].compare(pattern)) {
113+ string& token = tokens[1];
114+ size_t first_index = 0;
115+ while (token[first_index] == ' ') {
116+ ++first_index;
117+ }
118+ value = &token[first_index];
119+ return true;
120+ }
121+ }
122+ }
123+ return false;
174124 }
175125
176- // "/proc/acpi/battery/BATx/state" ファイルの
177- // "remaining capacity" を読み出し full_capacity_ から残量を計算する
178- size_t remaining_capacity = 0;
179- if (! matchData(remaining_capacity,
180- state_file_.c_str(), "remaining capacity")) {
181- return 0;
182- }
183126
184- size_t percent =
185- min(static_cast<size_t>(100), 100 * remaining_capacity / full_capacity_);
127+ bool matchData(size_t& value, const char* file, const char* pattern) const
128+ {
129+ string string_value;
130+ if (!matchData(string_value, file, pattern)) {
131+ return false;
132+ }
186133
187- return percent;
188- }
189-
190-
191- size_t remainingSecond(void) const
192- {
193- if (! is_available_) {
194- return 0;
134+ value = atoi(string_value.c_str());
135+ return true;
195136 }
196137
197- if (isCharging()) {
198- return 0;
138+
139+ bool loadFullCapacity(void)
140+ {
141+ // /proc/acpi/battery/BATx/info ファイルの "last full capacity" を読み出す
142+ if ((matchData(full_capacity_, info_file_.c_str(), "last full capacity")) &&
143+ (full_capacity_ > 0)) {
144+ is_available_ = true;
145+ return true;
146+ }
147+
148+ return false;
199149 }
200150
201- // "/proc/acpi/battery/BATx/state" ファイルの
202- // "present rate" [mW] と "remaining capacity" [mWh] を読み出し、
203- // バッテリーが使える時間を計算する
204- size_t present_rate = 0;
205- if (! matchData(present_rate, state_file_.c_str(), "present rate")) {
206- return 0;
151+
152+ bool isAvailable(void) const
153+ {
154+ return is_available_;
207155 }
208156
209- size_t remaining_capacity = 0;
210- if (! matchData(remaining_capacity,
211- state_file_.c_str(), "remaining capacity")) {
212- return 0;
157+
158+ bool isCharging(void) const
159+ {
160+ if (!is_available_) {
161+ return false;
162+ }
163+
164+ // 電源が接続されていないときに false を返す
165+ // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す
166+ string state;
167+ if (matchData(state, state_file_.c_str(), "charging state") &&
168+ ((!state.compare("charged")) || (!state.compare("charging")))) {
169+ return true;
170+ }
171+
172+ return false;
213173 }
214174
215- size_t second = 60 * 60 * remaining_capacity / max(present_rate,
216- static_cast<size_t>(1));
217- return second;
218- }
175+
176+ bool isCharged(void) const
177+ {
178+ if (!is_available_) {
179+ return false;
180+ }
181+
182+ // 電源が接続されていないときに false を返す
183+ // /proc/acpi/battery/BATx/state ファイルの "charging state" を読み出す
184+ string state;
185+ if (matchData(state, state_file_.c_str(), "charging state") &&
186+ (!state.compare("charged"))) {
187+ return true;
188+ }
189+
190+ return false;
191+ }
192+
193+
194+ size_t remainingPercent(void) const
195+ {
196+ if (!is_available_) {
197+ return 0;
198+ }
199+
200+ // "/proc/acpi/battery/BATx/state" ファイルの
201+ // "remaining capacity" を読み出し full_capacity_ から残量を計算する
202+ size_t remaining_capacity = 0;
203+ if (!matchData(remaining_capacity,
204+ state_file_.c_str(), "remaining capacity")) {
205+ return 0;
206+ }
207+
208+ size_t percent =
209+ min(static_cast<size_t>(100), 100 * remaining_capacity / full_capacity_);
210+
211+ return percent;
212+ }
213+
214+
215+ size_t remainingSecond(void) const
216+ {
217+ if (!is_available_) {
218+ return 0;
219+ }
220+
221+ if (isCharging()) {
222+ return 0;
223+ }
224+
225+ // "/proc/acpi/battery/BATx/state" ファイルの
226+ // "present rate" [mW] と "remaining capacity" [mWh] を読み出し、
227+ // バッテリーが使える時間を計算する
228+ size_t present_rate = 0;
229+ if (!matchData(present_rate, state_file_.c_str(), "present rate")) {
230+ return 0;
231+ }
232+
233+ size_t remaining_capacity = 0;
234+ if (!matchData(remaining_capacity,
235+ state_file_.c_str(), "remaining capacity")) {
236+ return 0;
237+ }
238+
239+ size_t second = 60 * 60 * remaining_capacity / max(present_rate,
240+ static_cast<size_t>(1));
241+ return second;
242+ }
219243 };
220244 #endif
221245
@@ -232,23 +256,29 @@
232256
233257 bool BatteryState::isAvailable(void) const
234258 {
235- return pimpl->isAvailable();
259+ return pimpl->isAvailable();
236260 }
237261
238262
239263 bool BatteryState::isCharging(void) const
240264 {
241- return pimpl->isCharging();
265+ return pimpl->isCharging();
266+}
267+
268+
269+bool BatteryState::isCharged(void) const
270+{
271+ return pimpl->isCharged();
242272 }
243273
244274
245275 size_t BatteryState::remainingPercent(void) const
246276 {
247- return pimpl->remainingPercent();
277+ return pimpl->remainingPercent();
248278 }
249279
250280
251281 size_t BatteryState::remainingSecond(void) const
252282 {
253- return pimpl->remainingSecond();
283+ return pimpl->remainingSecond();
254284 }
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/BatteryState.h
--- a/qlm_batmon/BatteryState.h Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/BatteryState.h Fri Nov 12 18:28:33 2010 +0000
@@ -15,54 +15,63 @@
1515
1616 namespace qrk
1717 {
18- //! PC バッテリー状態の取得
19- class BatteryState
20- {
21- public:
22- BatteryState(void);
23- ~BatteryState(void);
24-
25-
26- /*!
27- \brief バッテリー状態が取得可能か
28-
29- \retval true 取得可能
30- \retval false システムからバッテリー状態を取得できない
31- */
32- bool isAvailable(void) const;
18+ //! PC バッテリー状態の取得
19+ class BatteryState
20+ {
21+ public:
22+ BatteryState(void);
23+ ~BatteryState(void);
3324
3425
35- /*!
36- \brief 充電中か
26+ /*!
27+ \brief バッテリー状態が取得可能か
3728
38- \retval true 充電中
39- \retval false 放電中
40- */
41- bool isCharging(void) const;
29+ \retval true 取得可能
30+ \retval false システムからバッテリー状態を取得できない
31+ */
32+ bool isAvailable(void) const;
4233
4334
44- /*!
45- \brief バッテリー充電率
35+ /*!
36+ \brief 充電中か
4637
47- \return バッテリー充電率 [%]
48- */
49- size_t remainingPercent(void) const;
38+ \retval true 充電中
39+ \retval false 放電中
40+ */
41+ bool isCharging(void) const;
5042
5143
52- /*!
53- \brief バッテリーの推定残り時間
54-
55- \return バッテリーの推定残り時間 [sec]
56- */
57- size_t remainingSecond(void) const;
44+ /*!
45+ \brief 充電済みか
5846
59- private:
60- BatteryState(const BatteryState& rhs);
61- BatteryState& operator = (const BatteryState& rhs);
47+ \retval true 充電済み
48+ \retval false 放電済み
49+ */
50+ bool isCharged(void) const;
6251
63- struct pImpl;
64- std::auto_ptr<pImpl> pimpl;
65- };
52+
53+ /*!
54+ \brief バッテリー充電率
55+
56+ \return バッテリー充電率 [%]
57+ */
58+ size_t remainingPercent(void) const;
59+
60+
61+ /*!
62+ \brief バッテリーの推定残り時間
63+
64+ \return バッテリーの推定残り時間 [sec]
65+ */
66+ size_t remainingSecond(void) const;
67+
68+ private:
69+ BatteryState(const BatteryState& rhs);
70+ BatteryState& operator = (const BatteryState& rhs);
71+
72+ struct pImpl;
73+ std::auto_ptr<pImpl> pimpl;
74+ };
6675 }
6776
6877 #endif /* !QRK_BATTERY_STATE_H */
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/ChargingState.h
--- a/qlm_batmon/ChargingState.h Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/ChargingState.h Fri Nov 12 18:28:33 2010 +0000
@@ -12,9 +12,10 @@
1212
1313 //! 充電状態の定義
1414 typedef enum {
15- Unknown, //!< 対象外のシステム
16- Charging, //!< 充電中
17- Discharging, //!< バッテリ駆動中
15+ Unknown, //!< 対象外のシステム
16+ Charged, //!< 充電済み
17+ Charging, //!< 充電中
18+ Discharging, //!< バッテリ駆動中
1819 } ChargingState;
1920
2021 #endif /* !CHARGING_STATE_H */
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/DrawCharacter.cpp
--- a/qlm_batmon/DrawCharacter.cpp Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/DrawCharacter.cpp Fri Nov 12 18:28:33 2010 +0000
@@ -15,27 +15,28 @@
1515
1616 struct DrawCharacter::pImpl
1717 {
18- QString previous_base_name_;
19- QPixmap bar_pixmap_;
18+ QString previous_base_name_;
19+ QPixmap bar_pixmap_;
2020
2121
22- QString baseName(character_t& character, ChargingState state)
23- {
24- switch (state) {
25- case Charging:
26- return character.picture_charging;
27- break;
22+ QString baseName(character_t& character, ChargingState state)
23+ {
24+ switch (state) {
25+ case Charging:
26+ case Charged:
27+ return character.picture_charging;
28+ break;
2829
29- case Discharging:
30- return character.picture_discharging;
31- break;
30+ case Discharging:
31+ return character.picture_discharging;
32+ break;
3233
33- default:
34- case Unknown:
35- return character.picture_unknown;
36- break;
34+ default:
35+ case Unknown:
36+ return character.picture_unknown;
37+ break;
38+ }
3739 }
38- }
3940 };
4041
4142
@@ -54,36 +55,36 @@
5455 character_t& character,
5556 ChargingState state, size_t percent)
5657 {
57- QString base_name = pimpl->baseName(character, state);
58-
59- // ベース画像の描画
60- QPixmap base_pixmap(base_name);
61- painter.drawPixmap(QPoint(0, 0), base_pixmap);
62- base_rect = base_pixmap.rect();
63-
64- // 前回の描画画像と異なっていたら、背景の透過設定を更新する
65- bool update_background = false;
66- if (pimpl->previous_base_name_.compare(base_name)) {
67- region = base_pixmap.mask();
68- update_background = true;
69- }
58+ QString base_name = pimpl->baseName(character, state);
7059
71- // システム情報が不定でなければ、バッテリーの充電率を表示する
72- if (state != Unknown) {
60+ // ベース画像の描画
61+ QPixmap base_pixmap(base_name);
62+ painter.drawPixmap(QPoint(0, 0), base_pixmap);
63+ base_rect = base_pixmap.rect();
7364
74- // バッテリー充電率を描画
75- if (pimpl->bar_pixmap_.isNull()) {
76- pimpl->bar_pixmap_.load(character.percent_bar);
65+ // 前回の描画画像と異なっていたら、背景の透過設定を更新する
66+ bool update_background = false;
67+ if (pimpl->previous_base_name_.compare(base_name)) {
68+ region = base_pixmap.mask();
69+ update_background = true;
7770 }
78- QRect bar_rect(character.bar_position.x(),
79- character.bar_position.y(),
80- pimpl->bar_pixmap_.width(),
81- pimpl->bar_pixmap_.height());
82- size_t offset = bar_rect.height() * (100 - percent) / 100;
83- bar_rect.setY(bar_rect.y() + offset);
84- painter.drawPixmap(bar_rect, pimpl->bar_pixmap_);
85- }
8671
87- pimpl->previous_base_name_ = base_name;
88- return update_background;
72+ // システム情報が不定でなければ、バッテリーの充電率を表示する
73+ if (state != Unknown) {
74+
75+ // バッテリー充電率を描画
76+ if (pimpl->bar_pixmap_.isNull()) {
77+ pimpl->bar_pixmap_.load(character.percent_bar);
78+ }
79+ QRect bar_rect(character.bar_position.x(),
80+ character.bar_position.y(),
81+ pimpl->bar_pixmap_.width(),
82+ pimpl->bar_pixmap_.height());
83+ size_t offset = bar_rect.height() * (100 - percent) / 100;
84+ bar_rect.setY(bar_rect.y() + offset);
85+ painter.drawPixmap(bar_rect, pimpl->bar_pixmap_);
86+ }
87+
88+ pimpl->previous_base_name_ = base_name;
89+ return update_background;
8990 }
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/DrawCharacter.h
--- a/qlm_batmon/DrawCharacter.h Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/DrawCharacter.h Fri Nov 12 18:28:33 2010 +0000
@@ -23,19 +23,19 @@
2323 class DrawCharacter
2424 {
2525 public:
26- DrawCharacter(void);
27- ~DrawCharacter(void);
26+ DrawCharacter(void);
27+ ~DrawCharacter(void);
2828
29- //! 描画
30- bool draw(QPainter& painter, QRect& base_rect, QRegion& region,
31- character_t& character, ChargingState state, size_t percent);
29+ //! 描画
30+ bool draw(QPainter& painter, QRect& base_rect, QRegion& region,
31+ character_t& character, ChargingState state, size_t percent);
3232
3333 private:
34- DrawCharacter(const DrawCharacter& rhs);
35- DrawCharacter& operator = (const DrawCharacter& rhs);
34+ DrawCharacter(const DrawCharacter& rhs);
35+ DrawCharacter& operator = (const DrawCharacter& rhs);
3636
37- struct pImpl;
38- std::auto_ptr<pImpl> pimpl;
37+ struct pImpl;
38+ std::auto_ptr<pImpl> pimpl;
3939 };
4040
4141 #endif /* !DRAW_CHARACTER_H */
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/character_t.h
--- a/qlm_batmon/character_t.h Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/character_t.h Fri Nov 12 18:28:33 2010 +0000
@@ -17,13 +17,13 @@
1717 //! キャラクター情報の管理
1818 typedef struct
1919 {
20- QString name; //!< 表示名
20+ QString name; //!< 表示名
2121
22- QString picture_unknown; //!< システム情報が取得できないときの画像
23- QString picture_charging; //!< 充電中の画像
24- QString picture_discharging; //!< 充電していないときの画像
25- QString percent_bar; //!< 充電率を表示するためのバー
26- QPoint bar_position; //!< バーの表示位置
22+ QString picture_unknown; //!< システム情報が取得できないときの画像
23+ QString picture_charging; //!< 充電中の画像
24+ QString picture_discharging; //!< 充電していないときの画像
25+ QString percent_bar; //!< 充電率を表示するためのバー
26+ QPoint bar_position; //!< バーの表示位置
2727 } character_t;
2828
2929 #endif /* !CHARACTER_T_H */
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/main.cpp
--- a/qlm_batmon/main.cpp Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/main.cpp Fri Nov 12 18:28:33 2010 +0000
@@ -22,86 +22,87 @@
2222
2323 namespace
2424 {
25- class ArgsInformation
26- {
27- public:
28- bool geometry_specified;
29-
30-
31- ArgsInformation(void)
32- : geometry_specified(false)
25+ class ArgsInformation
3326 {
34- }
35- };
27+ public:
28+ bool geometry_specified;
3629
3730
38- void printHelp(const char* program_name)
39- {
40- const QString message =
41- QString("usage:\n"
42- "\t%1 [options]\n"
43- "\n"
44- "options\n"
45- " --help, -h print this message.\n"
46- " --version, -v output version infromation.\n"
47- " --geometry <position> Place to <position>.\n"
48- "\n"
49- "Report bugs to <satofumi@users.sourceforge.jp>.")
50- .arg(program_name);
51-
52- cout << message.toStdString() << endl;
53- }
31+ ArgsInformation(void)
32+ : geometry_specified(false)
33+ {
34+ }
35+ };
5436
5537
56- void printVersion(void)
57- {
58- cout << "qlm_batmon " << VersionString << endl;
59- }
38+ void printHelp(const char* program_name)
39+ {
40+ const QString message =
41+ QString("usage:\n"
42+ "\t%1 [options]\n"
43+ "\n"
44+ "options\n"
45+ " --help, -h print this message.\n"
46+ " --version, -v output version infromation.\n"
47+ " --geometry <position> Place to <position>.\n"
48+ "\n"
49+ "Report bugs to <satofumi@users.sourceforge.jp>.")
50+ .arg(program_name);
51+
52+ cout << message.toStdString() << endl;
53+ }
6054
6155
62- bool parseArgs(ArgsInformation& args, int argc, char *argv[])
63- {
64- for (int i = 1; i < argc; ++i) {
65- char* token = argv[i];
66-
67- if ((! strcmp(token, "-h") || (! strcmp(token, "--help")))) {
68- printHelp(argv[0]);
69- return false;
70-
71- } else if ((! strcmp(token, "-v") || (! strcmp(token, "--version")))) {
72- printVersion();
73- return false;
74-
75- } else if ((! strcmp("--geometry", token)) ||
76- (! strcmp("-geometry", token))) {
77- // 位置指定があれば、その位置に描画するようにする
78- args.geometry_specified = true;
79- }
56+ void printVersion(void)
57+ {
58+ cout << "qlm_batmon " << VersionString << endl;
8059 }
8160
82- return true;
83- }
61+
62+ bool parseArgs(ArgsInformation& args, int argc, char *argv[])
63+ {
64+ for (int i = 1; i < argc; ++i) {
65+ char* token = argv[i];
66+
67+ if ((!strcmp(token, "-h") || (!strcmp(token, "--help")))) {
68+ printHelp(argv[0]);
69+ return false;
70+
71+ } else if ((!strcmp(token, "-v") ||
72+ (!strcmp(token, "--version")))) {
73+ printVersion();
74+ return false;
75+
76+ } else if ((!strcmp("--geometry", token)) ||
77+ (!strcmp("-geometry", token))) {
78+ // 位置指定があれば、その位置に描画するようにする
79+ args.geometry_specified = true;
80+ }
81+ }
82+
83+ return true;
84+ }
8485 }
8586
8687
8788 //! main
8889 int main(int argc, char *argv[])
8990 {
90- ArgsInformation args;
91- if (! parseArgs(args, argc, argv)) {
92- return 1;
93- }
94-
95- QApplication app(argc, argv);
91+ ArgsInformation args;
92+ if (!parseArgs(args, argc, argv)) {
93+ return 1;
94+ }
9695
97- // ロケールの適用
98- QString locale = QLocale::system().name();
99- QTranslator translator;
100- translator.load("qlm_batmon_" + locale);
101- app.installTranslator(&translator);
96+ QApplication app(argc, argv);
10297
103- BatmonWidget widget(args.geometry_specified);
104- widget.show();
98+ // ロケールの適用
99+ QString locale = QLocale::system().name();
100+ QTranslator translator;
101+ translator.load("qlm_batmon_" + locale);
102+ app.installTranslator(&translator);
105103
106- return app.exec();
104+ BatmonWidget widget(args.geometry_specified);
105+ widget.show();
106+
107+ return app.exec();
107108 }
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/qlm_batmon.pro
--- a/qlm_batmon/qlm_batmon.pro Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/qlm_batmon.pro Fri Nov 12 18:28:33 2010 +0000
@@ -7,7 +7,7 @@
77
88 TEMPLATE = app
99 TARGET =
10-VERSION = -0.0.4
10+VERSION = -0.0.5
1111 DEPENDPATH += .
1212 INCLUDEPATH += .
1313
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/qlm_batmon_ja.qm
Binary file qlm_batmon/qlm_batmon_ja.qm has changed
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/qlm_batmon_ja.ts
--- a/qlm_batmon/qlm_batmon_ja.ts Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/qlm_batmon_ja.ts Fri Nov 12 18:28:33 2010 +0000
@@ -4,47 +4,62 @@
44 <context>
55 <name>BatmonWidget</name>
66 <message>
7- <location filename="BatmonWidget.cpp" line="94"/>
7+ <location filename="BatmonWidget.cpp" line="102"/>
88 <source>girl</source>
99 <translation>女の子</translation>
1010 </message>
1111 <message>
12- <location filename="BatmonWidget.cpp" line="104"/>
12+ <location filename="BatmonWidget.cpp" line="112"/>
1313 <source>pengui</source>
1414 <translation>りもペンギン</translation>
1515 </message>
1616 <message>
17- <location filename="BatmonWidget.cpp" line="133"/>
17+ <location filename="BatmonWidget.cpp" line="141"/>
18+ <source>Show always</source>
19+ <translation>常に表示する</translation>
20+ </message>
21+ <message>
22+ <location filename="BatmonWidget.cpp" line="148"/>
1823 <source>Hide while charging</source>
1924 <translation>充電中は表示しない</translation>
2025 </message>
2126 <message>
22- <location filename="BatmonWidget.cpp" line="143"/>
27+ <location filename="BatmonWidget.cpp" line="156"/>
28+ <source>Hide while charged</source>
29+ <translation>充電が完了したら隠す</translation>
30+ </message>
31+ <message>
32+ <location filename="BatmonWidget.cpp" line="166"/>
2333 <source>Ctrl+Q</source>
2434 <translation></translation>
2535 </message>
2636 <message>
27- <location filename="BatmonWidget.cpp" line="155"/>
37+ <location filename="BatmonWidget.cpp" line="178"/>
2838 <source>APM Battery Monitor</source>
2939 <translation>APM ばってりーもにたー</translation>
3040 </message>
3141 <message>
32- <location filename="BatmonWidget.cpp" line="278"/>
42+ <location filename="BatmonWidget.cpp" line="326"/>
3343 <source>charging: %1 [%]</source>
3444 <translation>充電中: %1 [%]</translation>
3545 </message>
3646 <message>
37- <location filename="BatmonWidget.cpp" line="283"/>
47+ <location filename="BatmonWidget.cpp" line="330"/>
48+ <source>charged</source>
49+ <translation>充電済み</translation>
50+ </message>
51+ <message>
52+ <location filename="BatmonWidget.cpp" line="335"/>
3853 <source>remaining: %1 [%]</source>
3954 <translation>容量: %1 [%]</translation>
4055 </message>
4156 <message>
42- <location filename="BatmonWidget.cpp" line="285"/>
57+ <location filename="BatmonWidget.cpp" line="337"/>
4358 <source>remaining: %1 [h] (%2 [%])</source>
4459 <translation>残り: %1 [h] (%2 [%])</translation>
4560 </message>
4661 <message>
47- <location filename="BatmonWidget.cpp" line="291"/>
62+ <location filename="BatmonWidget.cpp" line="344"/>
4863 <source>unknown system</source>
4964 <translation>不明なシステム</translation>
5065 </message>
@@ -52,7 +67,7 @@
5267 <context>
5368 <name>QAction</name>
5469 <message>
55- <location filename="BatmonWidget.cpp" line="142"/>
70+ <location filename="BatmonWidget.cpp" line="165"/>
5671 <source>Quit</source>
5772 <translation>終了</translation>
5873 </message>
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/split.cpp
--- a/qlm_batmon/split.cpp Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/split.cpp Fri Nov 12 18:28:33 2010 +0000
@@ -19,24 +19,24 @@
1919 const std::string& line, const char* split_pattern,
2020 bool continious_pattern)
2121 {
22- string buffer = line;
23- char* q = &buffer[0];
24- size_t n = line.size();
25- for (size_t i = 0; i < n; ++i, ++q) {
26- for (const char* p = split_pattern; *p != '\0'; ++p) {
27- if (*q == *p) {
28- *q = '\0';
29- break;
30- }
22+ string buffer = line;
23+ char* q = &buffer[0];
24+ size_t n = line.size();
25+ for (size_t i = 0; i < n; ++i, ++q) {
26+ for (const char* p = split_pattern; *p != '\0'; ++p) {
27+ if (*q == *p) {
28+ *q = '\0';
29+ break;
30+ }
31+ }
3132 }
32- }
3333
34- for (size_t i = 0; i < n; ++i) {
35- if ((buffer[i] != '\0') || (! continious_pattern)) {
36- string line = &buffer[i];
37- tokens.push_back(line);
38- i += line.size();
34+ for (size_t i = 0; i < n; ++i) {
35+ if ((buffer[i] != '\0') || (! continious_pattern)) {
36+ string line = &buffer[i];
37+ tokens.push_back(line);
38+ i += line.size();
39+ }
3940 }
40- }
41- return tokens.size();
41+ return tokens.size();
4242 }
diff -r 9856cfd83461 -r a03cd312d994 qlm_batmon/split.h
--- a/qlm_batmon/split.h Thu Apr 15 22:22:54 2010 +0000
+++ b/qlm_batmon/split.h Fri Nov 12 18:28:33 2010 +0000
@@ -16,19 +16,19 @@
1616
1717 namespace qrk
1818 {
19- /*!
20- \brief 指定文字による分割
19+ /*!
20+ \brief 指定文字による分割
2121
22- \param[out] tokens 分割後の文字列
23- \param[in] original 分割対象の文字列
24- \param[in] split_pattern 分割を行う文字の列
25- \param[in] continious_pattern 連続したセパレータを1つのセパレータとして扱う
22+ \param[out] tokens 分割後の文字列
23+ \param[in] original 分割対象の文字列
24+ \param[in] split_pattern 分割を行う文字の列
25+ \param[in] continious_pattern 連続したセパレータを1つのセパレータとして扱う
2626
27- \return 分割後のトークン数
28- */
29- size_t split(std::vector<std::string>& tokens,
30- const std::string& original, const char* split_pattern = " \t",
31- bool continious_pattern = true);
27+ \return 分割後のトークン数
28+ */
29+ size_t split(std::vector<std::string>& tokens,
30+ const std::string& original, const char* split_pattern = " \t",
31+ bool continious_pattern = true);
3232 }
3333
3434 #endif /* !QRK_SPLIT_H */
旧リポジトリブラウザで表示