suwako / UnixWallpaper アーカイブ

このリポジトリはアーカイブされています。読むだけで、プッシュやイシューの変更は出来ません。

master
ブランチ master
UnixWallpaper / src / fe / background.cc
1.6 KB、60行 生 Blame 履歴
1#include <FL/Fl_File_Chooser.H>
2
3#include <cstdlib>
4
5#include "background.hh"
6#include "misc.hh"
7#include "widget.hh"
8
9std::string fe::Background::sfp;
10
11namespace fe {
12 Background::Background() {}
13 Background::~Background() {}
14
15 uw::Mode Background::getMode() {
16 Fl_Choice *choice = Widget::getModeChoice();
17 if (!choice) return uw::Mode::TILE;
18
19 switch (choice->value()) {
20 case 0: return uw::Mode::TILE;
21 case 1: return uw::Mode::CENTER;
22 case 2: return uw::Mode::FILL;
23 default: return uw::Mode::TILE;
24 }
25 }
26
27 void Background::chooseImageCb(Fl_Widget *, void *) {
28 const char *homedir = std::getenv("HOME");
29 std::string defpath;
30
31 if (homedir) {
32 std::string userdir = std::string(homedir) + "/.local/share/wallpapers";
33 std::string localusr = "/usr/local/share/wallpapers";
34 std::string sysusr = "/usr/share/wallpapers";
35
36 if (Misc::isExist(userdir)) defpath = userdir;
37 else if (Misc::isExist(localusr)) defpath = localusr;
38 else defpath = sysusr;
39 }
40
41 Fl_File_Chooser chooser(defpath.c_str(), "*.{png,jpg}",
42 Fl_File_Chooser::SINGLE, "画像を御選択下さい・・・");
43 chooser.show();
44
45 while (chooser.shown()) Fl::wait();
46
47 if (chooser.value() != nullptr) {
48 setFilename(chooser.value());
49 Widget::getSetButton()->activate();
50 }
51 }
52
53 void Background::setWallpaperCb(Fl_Widget *, void *) {
54 if (!getFilename().empty()) {
55 uw::Background bg(getFilename());
56 bg.setWallpaper(getMode());
57 Widget::getSetButton()->deactivate();
58 }
59 }
60}