├── Makefile ├── README.md ├── README.rus.md ├── debian ├── startup-settings-amd64.deb └── startup-settings-i386.deb └── src ├── Makefile ├── autostart.cpp ├── autostart.hpp ├── fs.cpp ├── fs.hpp ├── gui.cpp ├── gui.glade ├── gui.hpp ├── item.cpp ├── item.hpp ├── main.cpp ├── startup-settings.desktop └── util.hpp /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | make -C src/ -s release 3 | 4 | install: 5 | cp startup-settings /usr/bin/ 6 | cp src/startup-settings.desktop /usr/share/applications/ 7 | mkdir -p /usr/share/startup-settings/ 8 | cp src/gui.glade /usr/share/startup-settings/ 9 | chmod -R 755 /usr/share/startup-settings/ 10 | 11 | uninstall: 12 | rm -f /usr/bin/startup-settings 13 | rm -f /usr/share/startup-settings/gui.glade 14 | rm -f /usr/share/applications/startup-settings.desktop 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Language: **[Русский](/README.rus.md)|English** 2 | 3 | # Startup Settings 4 | 5 | There is no handy tool to control startup in GNOME 3. If you want to add a custom command to 6 | startup, you have to create file `~/.config/autostart/file.desktop` manually. This 7 | simple program written in C++ and GTK 3 provides user friendly graphical interface for 8 | startup managing. The program is designed especially for GNOME 3, however it can also be 9 | used in any other desktop environment. 10 | 11 | ### Installation 12 | 13 | If you are using Debian/Ubuntu, you can install the application from package 14 | 15 | For amd64:
16 | `wget https://github.com/hant0508/startup-settings/raw/master/debian/startup-settings-amd64.deb`
17 | `sudo dpkg -i startup-settings-amd64.deb`
18 | For i386:
19 | `wget https://github.com/hant0508/startup-settings/raw/master/debian/startup-settings-i386.deb`
20 | `sudo dpkg -i startup-settings-i386.deb` 21 | 22 | If you've installed the package, you don't need to build the program from source code, go to [usage](#usage). 23 | 24 | ### Building 25 | 26 | - Installing dependencies
27 | Debian/Ubuntu: `sudo apt-get install g++ make git libgtk-3-dev`
28 | Arch/Manjaro x32: `sudo pacman -S gcc git make gtk3`
29 | Arch/Manjaro x64: `sudo pacman -S gcc-multilib git make gtk3`
30 | - Building
31 | `git clone https://github.com/hant0508/startup-settings.git`
32 | `cd startup-settings`
33 | `make` 34 | - Installing application
35 | `sudo make install` 36 | 37 | To save the disk space, you can delete all the downloaded files and dependencies after the installation. 38 | 39 | ### Usage 40 | 41 | After the installation you can find the program in application menu or run 42 | `startup-settings` in terminal. 43 | 44 | Enter startup command into the `Command` field. It can be: 45 | - full path to file: `/usr/bin/file.sh` 46 | - relative path to file in your your home directory: `scripts/file.sh` 47 | - command from [$PATH](https://en.wikipedia.org/wiki/PATH_(variable)): `firefox` 48 | 49 | Depending on the window manager, you can also use drag-and-drop. GNOME 3 allow 50 | even drag and drop files. 51 | 52 | ### Screenshots 53 | 54 | ![img](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/gif 1.gif) | ![img](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/gif 2.gif) 55 | :---:|:---: 56 | Usage on GNOME 3 | Drag and drop on GNOME 3 57 | 58 | 59 | ![alt-text](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/kde.png "KDE 5") | ![alt-text](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/cinnamon.png "Cinnamon 3") | ![alt-text](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/xfce4.png "XFCE 4") 60 | :-------------------------:|:-------------------------:|:-------------------------: 61 | KDE 5 | Cinnamon 3 | XFCE 4 62 | 63 | ### Feedback 64 | 65 | If you have any problems with the application, [open an 66 | issue](https://github.com/hant0508/startup-settings/issues/new). Write me [at 67 | email](mailto:hant0508@gmail.com?subject=GitHub issue | Startup), if you have no 68 | GitHub account. 69 | -------------------------------------------------------------------------------- /README.rus.md: -------------------------------------------------------------------------------- 1 | Language: **Русский|[English](/README.md)** 2 | 3 | # Startup Settings 4 | 5 | По умолчанию в GNOME 3 отсутствуют удобные инструменты для управления автозагрузкой. 6 | Для добавления пользовательской команды в автозагрузку необходимо вручную создать 7 | файл `~/.config/autostart/file.desktop`. Эта небольшая программа, написанная на C++ и 8 | GTK 3, предоставляет удобный графический интерфейс для управления автозагрузкой. 9 | Программа разработана специально для GNOME 3, однако может быть использована и в 10 | любой другой среде рабочего стола. 11 | 12 | ### Установка 13 | 14 | Если вы используете Debian/Ubuntu, вы можете установить приложение из пакета. 15 | 16 | Для amd64:
17 | `wget https://github.com/hant0508/startup-settings/raw/master/debian/startup-settings-amd64.deb`
18 | `sudo dpkg -i startup-settings-amd64.deb`
19 | Для i386:
20 | `wget https://github.com/hant0508/startup-settings/raw/master/debian/startup-settings-i386.deb`
21 | `sudo dpkg -i startup-settings-i386.deb` 22 | 23 | Если вы установили пакет, то вам не нужно собирать программу из исходного кода, переходите к [использованию](#Использование). 24 | 25 | ### Сборка 26 | 27 | - Установка зависимостей
28 | Debian/Ubuntu: `sudo apt-get install g++ make git libgtk-3-dev`
29 | Arch/Manjaro x32: `sudo pacman -S gcc git make gtk3`
30 | Arch/Manjaro x64: `sudo pacman -S gcc-multilib git make gtk3`
31 | - Сборка
32 | `git clone https://github.com/hant0508/startup-settings.git`
33 | `cd startup-settings`
34 | `make` 35 | - Установка приложения
36 | `sudo make install` 37 | 38 | Для освобождения места на диске вы можете удалить все загруженные файлы и зависимости 39 | после установки приложения. 40 | 41 | ### Использование 42 | 43 | После установки вы сможете найти программу в меню приложений или запустить 44 | `startup-settings` из терминала. 45 | 46 | Введите в поле `Command` команду автозагрузки. Это может быть: 47 | - полный путь к файлу: `/usr/bin/file.sh` 48 | - относительный путь к файлу в домашней папке: `scripts/file.sh` 49 | - команда из [$PATH](https://ru.wikipedia.org/wiki/PATH_(%D0%BF%D0%B5%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D0%B0%D1%8F)): `firefox` 50 | 51 | В зависимости от оконного менеджера, вы так же можете использовать drag-and-drop 52 | (перетаскивание). GNOME 3 разрешает даже перетаскивать файлы. 53 | 54 | ### Скриншоты 55 | 56 | ![img](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/gif 1.gif) | ![img](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/gif 2.gif) 57 | :---:|:---: 58 | Usage on GNOME 3 | Drag and drop on GNOME 3 59 | 60 | ![alt-text](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/kde.png "KDE 5") | ![alt-text](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/cinnamon.png "Cinnamon 3") | ![alt-text](https://raw.githubusercontent.com/hant0508/tmp/master/startup-settings/xfce4.png "XFCE 4") 61 | :-------------------------:|:-------------------------:|:-------------------------: 62 | KDE 5 | Cinnamon 3 | XFCE 4 63 | 64 | ### Обратная связь 65 | 66 | Если у вас возникли проблемы при работе с программой, сообщите о них на 67 | [GitHub](https://github.com/hant0508/startup-settings/issues/new) или 68 | [Вконтакте](https://vk.com/im?sel=116615188). Пишите мне [по электронной 69 | почте](mailto:hant0508@gmail.com?subject=GitHub issue | Startup), если у вас нет 70 | аккаунта на GitHub. 71 | -------------------------------------------------------------------------------- /debian/startup-settings-amd64.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hant0508-zz/startup-settings/6b1cc1700bb7f69babd0eff86dc7ca0505630ec5/debian/startup-settings-amd64.deb -------------------------------------------------------------------------------- /debian/startup-settings-i386.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hant0508-zz/startup-settings/6b1cc1700bb7f69babd0eff86dc7ca0505630ec5/debian/startup-settings-i386.deb -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | #CC=clang++ 3 | ACFLAGS = -O2 4 | #ACFLAGS = -Wall -g 5 | CFLAGS = -c -std=c++11 `pkg-config --cflags gtk+-3.0` 6 | LDFLAGS= -rdynamic `pkg-config --libs gtk+-3.0` 7 | SOURCES=main.cpp gui.cpp autostart.cpp item.cpp fs.cpp 8 | OBJECTS=$(SOURCES:.cpp=.o) 9 | EXECUTABLE=startup-settings 10 | 11 | all: $(SOURCES) $(EXECUTABLE) 12 | 13 | $(EXECUTABLE): $(OBJECTS) 14 | $(CC) $(OBJECTS) $(LDFLAGS) -o $@ 15 | 16 | .cpp.o: 17 | $(CC) $(CFLAGS)$(ACFLAGS) $< -o $@ 18 | 19 | remake: clean all 20 | 21 | debug: clean all 22 | gdb ./$(EXECUTABLE) 23 | 24 | run: all 25 | ./$(EXECUTABLE) 26 | 27 | release: all clean 28 | cp $(EXECUTABLE) ../ 29 | 30 | clean: 31 | rm -f $(OBJECTS) 32 | -------------------------------------------------------------------------------- /src/autostart.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "item.hpp" 31 | #include "autostart.hpp" 32 | #include "fs.hpp" 33 | #include "util.hpp" 34 | 35 | Autostart::Autostart () 36 | { 37 | if (!fs::exists (fs::home (S_CONFIG_PATH), true)) 38 | fs::mkdir (fs::home (S_CONFIG_PATH)); 39 | fs::cd (fs::home (S_CONFIG_PATH)); 40 | scan_folder(); 41 | } 42 | 43 | std::string Autostart::file_name (Item &it) const 44 | { 45 | std::string fname = it.get_name() + S_EXTENSION; 46 | 47 | for (size_t i = 0; i < fname.size(); ++i) 48 | if (fname.at(i) == '/') fname.at(i) = '_'; 49 | 50 | for (int i = 1; fs::exists (fs::pwd() + fname, true); ++i) 51 | fname = it.get_name() + std::to_string (i) + S_EXTENSION; 52 | 53 | it.set_id (fname); 54 | return fname; 55 | } 56 | 57 | bool Autostart::add_element (Item &it) 58 | { 59 | if (it.get_cmd() == S_EMPTY) return false; 60 | if (it.get_name() == S_EMPTY) it.set_name ("unnamed"); 61 | 62 | std::string fname = file_name (it); 63 | 64 | std::ofstream file (fs::pwd() + fname); 65 | 66 | file << "[Desktop Entry]\n"; 67 | file << "Name=" << it.get_name() << "\n"; 68 | file << "Comment=" << it.get_comment() << "\n"; 69 | file << "Exec=" << it.get_cmd() << "\n"; 70 | file << "Terminal=" << it.get_term() << "\n"; 71 | file << "Type=Application"; 72 | 73 | file.close(); 74 | 75 | list_.emplace (std::make_pair (fname, it)); 76 | 77 | return true; 78 | } 79 | 80 | void Autostart::remove_element (const std::string &id) 81 | { 82 | std::remove (std::string (fs::pwd() + id).c_str()); 83 | 84 | for (auto i = list_.begin(); i != list_.end(); ++i) 85 | if (i->first == id) 86 | { 87 | i = list_.erase (i); 88 | break; 89 | } 90 | } 91 | 92 | void Autostart::scan_folder () 93 | { 94 | std::vector f, files; 95 | f = fs::ls(); 96 | 97 | for (size_t i = 0; i < f.size(); ++i) 98 | { 99 | std::string fname = f.at(i); 100 | std::string test1 = fs::find_in_file (std::regex ("\\[Desktop Entry\\]"), fs::pwd() + fname); 101 | std::string test2 = fs::find_in_file (std::regex ("X\\-.*\\-Autostart\\-enabled=false"), fs::pwd() + fname); 102 | 103 | if (test1 != S_EMPTY && test2 == S_EMPTY) files.push_back (fname); 104 | } 105 | 106 | for (size_t i = 0; i < files.size(); ++i) 107 | { 108 | std::string cmd = fs::find_in_file (std::regex ("Exec=.*"), fs::pwd() + files.at(i)); 109 | std::string name = fs::find_in_file (std::regex ("Name=.*"), fs::pwd() + files.at(i)); 110 | std::string comment = fs::find_in_file (std::regex ("Comment=.*"), fs::pwd() + files.at(i)); 111 | std::string sterm = fs::find_in_file (std::regex ("Terminal= *true"), fs::pwd() + files.at(i)); 112 | 113 | if (cmd != S_EMPTY) cmd = cmd.substr (5); 114 | if (name != S_EMPTY) name = name.substr (5); 115 | if (comment != S_EMPTY) comment = comment.substr (8); 116 | bool term = (sterm == S_EMPTY ? false : true); 117 | 118 | Item it (cmd, name, comment, term); 119 | it.set_id (files.at(i)); 120 | list_.emplace (std::make_pair (files.at(i), it)); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/autostart.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef AUTOSTART_HPP 27 | #define AUTOSTART_HPP 28 | 29 | #include 30 | #include 31 | 32 | class Item; 33 | 34 | class Autostart 35 | { 36 | public: 37 | Autostart(); 38 | 39 | std::string file_name (Item &it) const; 40 | bool add_element (Item &it); 41 | void remove_element (const std::string &id); 42 | void scan_folder (); 43 | 44 | std::map get_list () const { return list_; } 45 | 46 | private: 47 | std::map list_; 48 | }; 49 | 50 | #endif // AUTOSTART_HPP 51 | -------------------------------------------------------------------------------- /src/fs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "fs.hpp" 34 | 35 | bool FS::exists (const std::string &file, bool silent = false) const 36 | { 37 | bool ex = (access (file.c_str(), F_OK ) != -1); 38 | if (!ex && !silent) std::cerr << ERR_NF + file << std::endl; 39 | return ex; 40 | } 41 | 42 | void FS::cd (const std::string &path) 43 | { 44 | WD_ = path; 45 | } 46 | 47 | void FS::print_vector (const std::vector &results) const 48 | { 49 | for (size_t i = 0; i < results.size(); ++i) 50 | std::cout << results.at(i) << std::endl; 51 | } 52 | 53 | void FS::fs_mkdir(const std::string &path) const 54 | { 55 | if (!fs::exists (path, true)) 56 | mkdir (path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); 57 | } 58 | 59 | std::string FS::pwd () const 60 | { 61 | return WD_; 62 | } 63 | 64 | std::string FS::home (const std::string &path) const 65 | { 66 | std::string home = getpwuid (getuid())->pw_dir; 67 | return std::string (home + S_SLASH + path); 68 | } 69 | 70 | std::vector FS::ls (const std::string &path) const 71 | { 72 | std::vector out; 73 | 74 | if (!exists (path)) 75 | { 76 | out.push_back (ERR_NF + path); 77 | return out; 78 | } 79 | 80 | DIR *dir = opendir (path.c_str()); 81 | struct dirent *ent; 82 | 83 | while ((ent = readdir (dir)) != NULL) 84 | out.push_back (std::string(ent->d_name)); 85 | 86 | closedir (dir); 87 | return out; 88 | } 89 | 90 | std::vector FS::find (const std::regex &mask, const std::string &path) 91 | { 92 | std::vector out, input = ls (path); 93 | 94 | if (!exists (path)) 95 | { 96 | out.push_back (ERR_NF + path); 97 | return out; 98 | } 99 | 100 | for (size_t i = 0; i < input.size(); ++i) 101 | if (regex_match (input.at(i), mask)) 102 | out.push_back (input.at(i)); 103 | 104 | return out; 105 | } 106 | 107 | std::string FS::find_in_file (const std::regex &mask, const std::string &fname) 108 | { 109 | if (!exists (fname)) return ERR_NF + fname; 110 | 111 | std::string out; 112 | std::ifstream input (fname); 113 | 114 | if (!input) return S_EMPTY; 115 | 116 | while (getline (input, out)) 117 | if (regex_match (out, mask)) 118 | return out; 119 | 120 | return S_EMPTY; 121 | } 122 | 123 | // namespace fs 124 | 125 | bool fs::exists (const std::string &file, bool silent) 126 | { 127 | return FS::inst().exists (file, silent); 128 | } 129 | 130 | void fs::cd (const std::string &path) 131 | { 132 | FS::inst().cd (path); 133 | } 134 | 135 | void fs::print_vector (const std::vector &results) 136 | { 137 | FS::inst().print_vector (results); 138 | } 139 | 140 | void fs::mkdir(const std::string &path) 141 | { 142 | FS::inst().fs_mkdir (path); 143 | } 144 | 145 | std::string fs::pwd () 146 | { 147 | return FS::inst().pwd(); 148 | } 149 | 150 | std::string fs::home (const std::string &path) 151 | { 152 | return FS::inst().home (path); 153 | } 154 | 155 | std::vector fs::ls (const std::string &path) 156 | { 157 | return FS::inst().ls (path); 158 | } 159 | 160 | std::vector fs::find (const std::regex &mask, const std::string &path) 161 | { 162 | return FS::inst().find (mask, path); 163 | } 164 | 165 | std::string fs::find_in_file (const std::regex &mask, const std::string &fname) 166 | { 167 | return FS::inst().find_in_file (mask, fname); 168 | } 169 | -------------------------------------------------------------------------------- /src/fs.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef FS_HPP 27 | #define FS_HPP 28 | 29 | #include 30 | #include 31 | #include 32 | #include "util.hpp" 33 | 34 | class FS 35 | { 36 | public: 37 | 38 | static FS& inst() 39 | { 40 | static FS fs; 41 | return fs; 42 | } 43 | 44 | bool exists (const std::string &file, bool silent) const; 45 | void cd (const std::string &path); 46 | void print_vector (const std::vector &result) const; 47 | void fs_mkdir(const std::string &path) const; 48 | 49 | std::string pwd () const; 50 | std::string home (const std::string &path) const; 51 | std::vector ls (const std::string &path) const; 52 | std::vector find (const std::regex &mask, const std::string &path); 53 | std::string find_in_file (const std::regex &mask, const std::string &fname); 54 | 55 | private: 56 | FS () {} 57 | FS (const FS&) {} 58 | FS& operator= (const FS&); 59 | 60 | std::string WD_; 61 | }; 62 | 63 | namespace fs 64 | { 65 | bool exists (const std::string &file, bool silent = false); 66 | void cd (const std::string &path = FS::inst().home (S_EMPTY)); 67 | void print_vector (const std::vector &results); 68 | void mkdir(const std::string &path); 69 | 70 | std::string pwd (); 71 | std::string home (const std::string &path = S_EMPTY); 72 | std::vector ls (const std::string &path = FS::inst().pwd()); 73 | std::vector find (const std::regex &mask, const std::string &path = FS::inst().pwd()); 74 | std::string find_in_file (const std::regex &mask, const std::string &fname); 75 | 76 | } // namespace fs 77 | 78 | #endif // FS_HPP 79 | -------------------------------------------------------------------------------- /src/gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #include "gui.hpp" 29 | #include "fs.hpp" 30 | #include "item.hpp" 31 | #include "util.hpp" 32 | 33 | extern "C" void on_remove_clicked (GtkButton *button, gpointer row); 34 | 35 | void GUI::create_window() const 36 | { 37 | GtkBuilder *builder; 38 | builder = gtk_builder_new(); 39 | 40 | std::string path; 41 | if (fs::exists (std::string ("gui.glade"), true)) 42 | path = std::string ("gui.glade"); 43 | else if (fs::exists (std::string ("src/gui.glade"), true)) 44 | path = std::string ("src/gui.glade"); 45 | else path = S_SETTINGS_PATH; 46 | 47 | if (!fs::exists (path)) exit (1); 48 | 49 | gtk_builder_add_from_file (builder, path.c_str(), NULL); 50 | gtk_builder_connect_signals (builder, NULL); 51 | 52 | GtkWidget *window; 53 | window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); 54 | 55 | if (!window) exit (1); 56 | gtk_window_set_title (GTK_WINDOW (window), "Startup Settings"); 57 | g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); 58 | 59 | gtk_widget_show (window); 60 | } 61 | 62 | void GUI::create_list (GtkWidget *listbox, const std::map &items) 63 | { 64 | list_ = listbox; 65 | 66 | for (auto i = items.begin(); i != items.end(); ++i) 67 | create_row (i->second, -1); 68 | 69 | gtk_widget_show_all (list_); 70 | } 71 | 72 | void GUI::create_row (const Item &it, int pos) 73 | { 74 | std::string sname = it.get_name(); 75 | std::string scmd = it.get_cmd(); 76 | std::string scomment = it.get_comment(); 77 | std::string sid = it.get_id (); 78 | const gchar *name = sname.c_str(); 79 | const gchar *cmd = scmd.c_str(); 80 | const gchar *comment = scomment.c_str(); 81 | const gchar *id = sid.c_str(); 82 | 83 | GtkWidget *row = gtk_list_box_row_new(); 84 | GtkWidget *grid = gtk_grid_new(); 85 | GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); 86 | GtkWidget *button = gtk_button_new_with_label ("Remove"); 87 | GtkWidget *l1 = gtk_label_new (name); 88 | GtkWidget *l2 = gtk_label_new (cmd); 89 | GtkWidget *l3 = gtk_label_new (comment); 90 | 91 | gtk_widget_set_halign (l1, GTK_ALIGN_START); 92 | gtk_widget_set_halign (l2, GTK_ALIGN_START); 93 | gtk_widget_set_halign (l3, GTK_ALIGN_START); 94 | 95 | PangoAttrList *atl = pango_attr_list_new(); 96 | pango_attr_list_change (atl, pango_attr_weight_new (PANGO_WEIGHT_SEMIBOLD)); 97 | pango_attr_list_change (atl, pango_attr_size_new (17000)); 98 | gtk_label_set_attributes (GTK_LABEL (l1), atl); 99 | 100 | gtk_label_set_line_wrap (GTK_LABEL (l3), true); 101 | gtk_label_set_line_wrap_mode (GTK_LABEL (l3), PANGO_WRAP_CHAR); 102 | gtk_label_set_line_wrap (GTK_LABEL (l2), true); 103 | gtk_label_set_line_wrap_mode (GTK_LABEL (l2), PANGO_WRAP_CHAR); 104 | 105 | gtk_label_set_selectable (GTK_LABEL (l1), true); 106 | gtk_label_set_selectable (GTK_LABEL (l2), true); 107 | gtk_label_set_selectable (GTK_LABEL (l3), true); 108 | 109 | gtk_container_add (GTK_CONTAINER (box), l1); 110 | gtk_container_add (GTK_CONTAINER (box), l2); 111 | gtk_container_add (GTK_CONTAINER (box), l3); 112 | 113 | gtk_widget_set_hexpand (button, true); 114 | gtk_widget_set_halign (button, GTK_ALIGN_END); 115 | 116 | gtk_grid_attach (GTK_GRID (grid), box, 0, 0, 1, 1); 117 | gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1); 118 | gtk_widget_set_margin_start (grid, 3); 119 | gtk_widget_set_margin_end (grid, 3); 120 | gtk_widget_set_margin_top (grid, 2); 121 | 122 | gtk_widget_set_name (row, id); 123 | 124 | gtk_container_add (GTK_CONTAINER (row), grid); 125 | gtk_list_box_insert (GTK_LIST_BOX (list_), row, pos); 126 | 127 | g_signal_connect (button, "clicked", G_CALLBACK (on_remove_clicked), row); 128 | 129 | gtk_widget_show_all (list_); 130 | } 131 | 132 | void GUI::remove_row (GtkWidget *row) 133 | { 134 | gtk_container_remove (GTK_CONTAINER (list_), row); 135 | gtk_widget_show_all (list_); 136 | } 137 | 138 | void GUI::fill_entries (GtkWidget *box) 139 | { 140 | GtkWidget *wcmd, *wname, *wcomment, *wterm; 141 | 142 | find_child (box, &wcmd, "command"); 143 | find_child (box, &wname, "name"); 144 | find_child (box, &wcomment, "comment"); 145 | find_child (box, &wterm, "terminal"); 146 | 147 | std::string cmd = gtk_entry_get_text (GTK_ENTRY (wcmd)); 148 | if (cmd == S_SPACE) cmd = S_EMPTY; 149 | else if (cmd.substr(0, 7) == S_LOCAL_FILE) cmd = cmd.substr(7); 150 | 151 | for (size_t i = 1; i < cmd.size(); ++i) 152 | if ((cmd.at(i) == '(' || cmd.at(i) == ')') && cmd.at(i - 1) != '\\') 153 | { 154 | cmd.insert(i, 1, '\\'); 155 | ++i; 156 | } 157 | 158 | cmd = regex_replace (cmd, std::regex("%20"), "\\ "); 159 | cmd = regex_replace (cmd, std::regex("\n"), ""); 160 | cmd = regex_replace (cmd, std::regex("\r"), ""); 161 | 162 | std::string name = cmd; 163 | std::string comment = S_EMPTY; 164 | 165 | bool active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wterm)); 166 | std::string term = (active ? std::string (" in terminal") : S_EMPTY); 167 | 168 | if (!name.empty() && name.at(0) == '/') name.erase(0, 1); 169 | 170 | for (size_t i = 1; i < name.size(); ++i) 171 | { 172 | if (name.at(i) == '/' && (name.at(i - 1) == ' ' || name.at(i - 1) == '\"')) 173 | break; 174 | 175 | else if (name.at(i) == '/' && name.at(i - 1) != ' ' && name.at(i - 1) != '\"') 176 | { 177 | name = name.substr (i + 1); 178 | i = 0; 179 | } 180 | } 181 | 182 | if (name_is_edited_) name = gtk_entry_get_text (GTK_ENTRY (wname)); 183 | if (name != S_EMPTY) comment = std::string ("Run ") + name + term; 184 | 185 | gtk_entry_set_text (GTK_ENTRY (wcmd), cmd.c_str()); 186 | if (!comment_is_edited_) gtk_entry_set_text (GTK_ENTRY (wcomment), comment.c_str()); 187 | gtk_entry_set_text (GTK_ENTRY (wname), name.c_str()); 188 | } 189 | 190 | void GUI::reset_entries (GtkWidget *box) 191 | { 192 | name_is_edited_ = false; 193 | comment_is_edited_ = false; 194 | 195 | GtkWidget *wcmd, *wname, *wcomment; 196 | find_child (box, &wcmd, "command"); 197 | find_child (box, &wname, "name"); 198 | find_child (box, &wcomment, "comment"); 199 | 200 | gtk_entry_set_text (GTK_ENTRY (wcmd), ""); 201 | gtk_entry_set_text (GTK_ENTRY (wname), ""); 202 | gtk_entry_set_text (GTK_ENTRY (wcomment), ""); 203 | } 204 | 205 | void GUI::entry_changed (const gchar *name) 206 | { 207 | if (std::string (name) == std::string ("name")) 208 | name_is_edited_ = true; 209 | else comment_is_edited_ = true; 210 | } 211 | 212 | void GUI::find_child (GtkWidget *parent, GtkWidget **aim, const gchar *name) const 213 | { 214 | if (std::string(gtk_widget_get_name (parent)) == std::string(name)) 215 | *aim = parent; 216 | 217 | else if (GTK_IS_BIN (parent)) 218 | { 219 | GtkWidget *child = gtk_bin_get_child (GTK_BIN(parent)); 220 | find_child (child, aim, name); 221 | } 222 | 223 | else if (GTK_IS_CONTAINER (parent)) 224 | { 225 | GList *children = gtk_container_get_children (GTK_CONTAINER (parent)); 226 | while (children != NULL) 227 | { 228 | GtkWidget *child = GTK_WIDGET(children->data); 229 | find_child (child, aim, name); 230 | children = g_list_next (children); 231 | } 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /src/gui.glade: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | window 7 | False 8 | 640 9 | 480 10 | 11 | 12 | 13 | box 14 | True 15 | False 16 | 30 17 | 30 18 | 30 19 | 30 20 | vertical 21 | 22 | 23 | grid 24 | True 25 | False 26 | 27 | 28 | cmd_lab 29 | True 30 | False 31 | Command: 32 | 33 | 34 | 0 35 | 0 36 | 37 | 38 | 39 | 40 | command 41 | True 42 | True 43 | Here you can use: 44 | /full/path/to/file 45 | path/to/file (in home directory) 46 | command 47 | drag-and-drop 48 | 200 49 | gtk-clear 50 | 51 | 52 | 53 | 54 | 1 55 | 0 56 | 57 | 58 | 59 | 60 | False 61 | True 62 | 0 63 | 64 | 65 | 66 | 67 | True 68 | True 69 | 10 70 | 71 | 72 | grid_under 73 | True 74 | False 75 | 76 | 77 | nam_lab 78 | True 79 | False 80 | 10 81 | 10 82 | Name : 83 | 84 | 85 | 0 86 | 0 87 | 88 | 89 | 90 | 91 | com_lab 92 | True 93 | False 94 | 10 95 | Comment : 96 | 97 | 98 | 0 99 | 1 100 | 101 | 102 | 103 | 104 | name 105 | True 106 | True 107 | 10 108 | 10 109 | 200 110 | gtk-clear 111 | 112 | 113 | 114 | 115 | 116 | 117 | 1 118 | 0 119 | 120 | 121 | 122 | 123 | comment 124 | True 125 | True 126 | 10 127 | 200 128 | gtk-clear 129 | 130 | 131 | 132 | 133 | 134 | 135 | 1 136 | 1 137 | 138 | 139 | 140 | 141 | True 142 | False 143 | 1 144 | Run in terminal 145 | 146 | 147 | 0 148 | 2 149 | 150 | 151 | 152 | 153 | 154 | terminal 155 | True 156 | True 157 | False 158 | top 159 | True 160 | 161 | 162 | 163 | 1 164 | 2 165 | 166 | 167 | 168 | 169 | 170 | 171 | True 172 | False 173 | Details 174 | 175 | 176 | 177 | 178 | False 179 | True 180 | 1 181 | 182 | 183 | 184 | 185 | Add to autostart 186 | True 187 | True 188 | True 189 | 10 190 | 10 191 | 192 | 193 | 194 | False 195 | True 196 | 2 197 | 198 | 199 | 200 | 201 | True 202 | True 203 | in 204 | 300 205 | 240 206 | 207 | 208 | True 209 | False 210 | natural 211 | 212 | 213 | True 214 | False 215 | 216 | 217 | 218 | 219 | 220 | 221 | True 222 | True 223 | 3 224 | 225 | 226 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /src/gui.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef GUI_HPP 27 | #define GUI_HPP 28 | 29 | #include 30 | #include 31 | 32 | class Item; 33 | 34 | class GUI 35 | { 36 | public: 37 | GUI(): name_is_edited_ (false), comment_is_edited_ (false) {} 38 | 39 | void create_window () const; 40 | void create_list (GtkWidget *listbox, const std::map &items); 41 | void create_row (const Item &it, int pos); 42 | void remove_row (GtkWidget *row); 43 | void fill_entries (GtkWidget *box); 44 | void reset_entries (GtkWidget *box); 45 | 46 | void entry_changed (const gchar *name); 47 | void find_child (GtkWidget *parent, GtkWidget **aim, const gchar *name) const; 48 | 49 | private: 50 | GtkWidget *list_; 51 | bool name_is_edited_, comment_is_edited_; 52 | }; 53 | 54 | #endif // GUI_HPP 55 | -------------------------------------------------------------------------------- /src/item.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "item.hpp" 27 | #include 28 | 29 | Item::Item (const std::string &cmd, const std::string &name, const std::string &comment, bool term) 30 | { 31 | set_cmd (cmd); 32 | set_name (name); 33 | set_comment (comment); 34 | set_term (term); 35 | } 36 | 37 | void Item::set_cmd (const std::string &cmd) 38 | { 39 | cmd_ = cmd; 40 | } 41 | 42 | void Item::set_name (const std::string &name) 43 | { 44 | name_ = name; 45 | } 46 | 47 | void Item::set_comment (const std::string &comment) 48 | { 49 | comment_ = comment; 50 | } 51 | 52 | void Item::set_term (bool term) 53 | { 54 | term_ = (term ? std::string ("true") : std::string ("false")); 55 | } 56 | 57 | void Item::set_id (std::string id) 58 | { 59 | id_ = id; 60 | } 61 | -------------------------------------------------------------------------------- /src/item.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef ITEM_HPP 27 | #define ITEM_HPP 28 | 29 | #include 30 | 31 | class Item 32 | { 33 | public: 34 | Item (const std::string &cmd, const std::string &name, const std::string &comment, bool term); 35 | 36 | void set_cmd (const std::string &cmd); 37 | void set_name (const std::string &name); 38 | void set_comment (const std::string &comment); 39 | void set_term (bool term); 40 | 41 | void set_id (std::string id); 42 | 43 | std::string get_cmd () const { return cmd_; } 44 | std::string get_name () const { return name_; } 45 | std::string get_comment () const { return comment_; } 46 | std::string get_term () const { return term_; } 47 | 48 | std::string get_id () const { return id_; } 49 | 50 | private: 51 | std::string cmd_, name_, comment_, term_, id_; 52 | }; 53 | 54 | #endif // ITEM_HPP 55 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include "gui.hpp" 28 | #include "autostart.hpp" 29 | #include "item.hpp" 30 | 31 | Autostart autostart; 32 | GUI gui; 33 | 34 | extern "C" void on_entry_key_press (GtkWidget *entry, GdkEvent*, gpointer box) 35 | { 36 | gui.entry_changed (gtk_widget_get_name (GTK_WIDGET (entry))); 37 | gui.fill_entries (GTK_WIDGET (box)); 38 | } 39 | 40 | extern "C" void on_entry_clipboard (GtkEntry *entry, gpointer box) 41 | { 42 | gui.entry_changed (gtk_widget_get_name (GTK_WIDGET (entry))); 43 | gui.fill_entries (GTK_WIDGET (box)); 44 | } 45 | 46 | extern "C" void on_command_changed (GtkEditable *entry, gpointer box) 47 | { 48 | gui.fill_entries (GTK_WIDGET (box)); 49 | } 50 | 51 | extern "C" void on_terminal_toggled (GtkToggleButton *term, gpointer box) 52 | { 53 | gui.fill_entries (GTK_WIDGET (box)); 54 | } 55 | 56 | extern "C" void on_remove_clicked (GtkButton *button, gpointer row) 57 | { 58 | autostart.remove_element (gtk_widget_get_name (GTK_WIDGET (row))); 59 | gui.remove_row (GTK_WIDGET (row)); 60 | } 61 | 62 | extern "C" void on_window_show (GtkWidget *window, gpointer listbox) 63 | { 64 | gui.create_list (GTK_WIDGET (listbox), autostart.get_list()); 65 | } 66 | 67 | extern "C" void on_command_clear_press (GtkEntry *cmd, GtkEntryIconPosition*, GdkEvent*, gpointer box) 68 | { 69 | gtk_entry_set_text (cmd, ""); 70 | gui.fill_entries (GTK_WIDGET (box)); 71 | } 72 | 73 | extern "C" void on_entry_clear_press (GtkEntry *entry, GtkEntryIconPosition*, GdkEvent*, gpointer) 74 | { 75 | gtk_entry_set_text (entry, ""); 76 | gui.entry_changed (gtk_widget_get_name (GTK_WIDGET (entry))); 77 | } 78 | 79 | extern "C" void on_button_clicked (GtkButton *button, gpointer box) 80 | { 81 | GtkWidget *wcmd, *wname, *wcomment, *wterm; 82 | 83 | gui.find_child (GTK_WIDGET (box), &wcmd, "command"); 84 | gui.find_child (GTK_WIDGET (box), &wname, "name"); 85 | gui.find_child (GTK_WIDGET (box), &wcomment, "comment"); 86 | gui.find_child (GTK_WIDGET (box), &wterm, "terminal"); 87 | 88 | const gchar *cmd = gtk_entry_get_text (GTK_ENTRY (wcmd)); 89 | const gchar *name = gtk_entry_get_text (GTK_ENTRY (wname)); 90 | const gchar *comment = gtk_entry_get_text (GTK_ENTRY (wcomment)); 91 | const gboolean term = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wterm)); 92 | 93 | Item it (cmd, name, comment, term); 94 | 95 | if (!autostart.add_element (it)) return; 96 | gui.create_row (it, 0); 97 | gui.reset_entries (GTK_WIDGET (box)); 98 | } 99 | 100 | int main (int argc, char *argv[]) 101 | { 102 | gtk_init (&argc, &argv); 103 | gui.create_window(); 104 | 105 | gtk_main (); 106 | } 107 | -------------------------------------------------------------------------------- /src/startup-settings.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Name=Startup Settings 4 | Comment=Manage your startup applications 5 | Exec=startup-settings 6 | Terminal=false 7 | Type=Application 8 | Icon=preferences-system 9 | Categories=GTK;Settings 10 | -------------------------------------------------------------------------------- /src/util.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016 Dmitry Ivanov 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef UTIL_HPP 27 | #define UTIL_HPP 28 | 29 | const char S_TRUE[] = "true"; 30 | const char S_FALSE[] = "false"; 31 | const char S_EXTENSION[] = ".desktop"; 32 | const char S_LOCAL_FILE[] = "file://"; 33 | const char S_SLASH[] = "/"; 34 | const char S_SPACE[] = " "; 35 | const char S_EMPTY[] = ""; 36 | const char S_CONFIG_PATH[] = ".config/autostart/"; 37 | const char S_SETTINGS_PATH[] = "/usr/share/startup-settings/gui.glade"; 38 | const char ERR_NF[] = "File not found or permission denied: "; 39 | 40 | #endif // UTIL_HPP 41 | --------------------------------------------------------------------------------