1 //===========================================
2 //  Lumina-DE source code
3 //  Copyright (c) 2014, Ken Moore
4 //  Available under the 3-clause BSD license
5 //  See the LICENSE file for full details
6 //===========================================
7 #ifdef __NetBSD__
8 #include "LuminaOS.h"
9 #include <unistd.h>
10 #include <stdio.h> // Needed for BUFSIZ
11 
OSName()12 QString LOS::OSName(){ return "NetBSD"; }
13 
14 //OS-specific prefix(s)
15 // NOTE: PREFIX, L_ETCDIR, L_SHAREDIR are defined in the OS-detect.pri project file and passed in
LuminaShare()16 QString LOS::LuminaShare(){ return (L_SHAREDIR+"/lumina-desktop/"); } //Install dir for Lumina share files
AppPrefix()17 QString LOS::AppPrefix(){ return "/usr/local/"; } //Prefix for applications
SysPrefix()18 QString LOS::SysPrefix(){ return "/usr/"; } //Prefix for system
19 
20 //OS-specific application shortcuts (*.desktop files)
ControlPanelShortcut()21 QString LOS::ControlPanelShortcut(){ return ""; } //system control panel
AppStoreShortcut()22 QString LOS::AppStoreShortcut(){ return ""; } //graphical app/pkg manager
23 //OS-specific RSS feeds (Format: QStringList[ <name>::::<url> ]; )
RSSFeeds()24 QStringList LOS::RSSFeeds(){
25   QStringList feeds;
26   feeds << "NetBSD News::::http://www.netbsd.org/changes/rss-netbsd.xml";
27   return feeds;
28 }
29 
30 // ==== ExternalDevicePaths() ====
ExternalDevicePaths()31 QStringList LOS::ExternalDevicePaths(){
32     //Returns: QStringList[<type>::::<filesystem>::::<path>]
33       //Note: <type> = [USB, HDRIVE, DVD, SDCARD, UNKNOWN]
34 
35   //Not implemented yet
36   return QStringList();
37 }
38 
39 //Read screen brightness information
ScreenBrightness()40 int LOS::ScreenBrightness(){
41   //Returns: Screen Brightness as a percentage (0-100, with -1 for errors)
42   return -1;  //not implemented yet
43 }
44 
45 //Set screen brightness
setScreenBrightness(int)46 void LOS::setScreenBrightness(int){ //percent: 0-100
47   //not implemented yet
48 }
49 
50 //Read the current volume
audioVolume()51 int LOS::audioVolume(){
52   //Returns: audio volume as a percentage (0-100, with -1 for errors)
53   return -1; //Not implemented yet
54 }
55 
56 //Set the current volume
setAudioVolume(int)57 void LOS::setAudioVolume(int){ //percent: 0-100
58   //not implemented yet
59 }
60 
61 //Change the current volume a set amount (+ or -)
changeAudioVolume(int)62 void LOS::changeAudioVolume(int){ //percent difference (+ or -)
63   //not implemented yet
64 }
65 
66 //Check if a graphical audio mixer is installed
hasMixerUtility()67 bool LOS::hasMixerUtility(){
68   return false; //not implemented yet
69 }
70 
71 //Launch the graphical audio mixer utility
startMixerUtility()72 void LOS::startMixerUtility(){
73   //not implemented yet
74 }
75 
76 //Check for user system permission (shutdown/restart)
userHasShutdownAccess()77 bool LOS::userHasShutdownAccess(){
78   //User needs to be a part of the operator group to be able to run the shutdown command
79   QStringList groups = LUtils::getCmdOutput("id -Gn").join(" ").split(" ");
80   return groups.contains("operator");
81 }
82 
83 //Check for whether the system is safe to power off (no updates being perfomed)
systemPerformingUpdates()84 bool LOS::systemPerformingUpdates(){
85   return false; //Not implemented yet
86 }
87 
88 //Return the details of any updates which are waiting to apply on shutdown
systemPendingUpdates()89 QString LOS::systemPendingUpdates(){
90   return "";
91 }
92 
93 //System Shutdown
systemShutdown(bool)94 void LOS::systemShutdown(bool){ //start poweroff sequence
95   //INPUT: skip updates (true/false)
96   QProcess::startDetached("shutdown -p now");
97 }
98 
99 //System Restart
systemRestart(bool)100 void LOS::systemRestart(bool){ //start reboot sequence
101   //INPUT: skip updates (true/false)
102   QProcess::startDetached("shutdown -r now");
103 }
104 
105 //Check for suspend support
systemCanSuspend()106 bool LOS::systemCanSuspend(){
107   return false;
108 }
109 
110 //Put the system into the suspend state
systemSuspend()111 void LOS::systemSuspend(){
112 
113 }
114 
115 //Battery Availability
hasBattery()116 bool LOS::hasBattery(){
117   return false; //not implemented yet
118 }
119 
120 //Battery Charge Level
batteryCharge()121 int LOS::batteryCharge(){ //Returns: percent charge (0-100), anything outside that range is counted as an error
122   return -1;  //not implemented yet
123 }
124 
125 //Battery Charging State
batteryIsCharging()126 bool LOS::batteryIsCharging(){
127   return false; //not implemented yet
128 }
129 
130 //Battery Time Remaining
batterySecondsLeft()131 int LOS::batterySecondsLeft(){ //Returns: estimated number of seconds remaining
132   return 0; //not implemented yet
133 }
134 
135 //File Checksums
Checksums(QStringList filepaths)136 QStringList LOS::Checksums(QStringList filepaths){ //Return: checksum of the input file
137   //on NetBSD md5(1) has the following layout
138   //$ md5 DESCR Makefile
139   //MD5 (DESCR) = 6aaa128cf0466792be6f6d15e4589dfb
140   //MD5 (Makefile) = 4787f3145bba2a3cc393cdd812c5d18b
141 
142   QStringList info = LUtils::getCmdOutput("md5 \""+filepaths.join("\" \"")+"\"");
143   for(int i=0; i<info.length(); i++){
144     if( !info[i].contains(" = ") ){ info.removeAt(i); i--; }
145     else{
146       //Strip out the extra information
147       info[i] = info[i].section(" = ",1,1);
148     }
149   }
150   return info;
151 }
152 
153 //file system capacity
FileSystemCapacity(QString dir)154 QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as give by the df command
155   // on NetBSD, df has the following layout:
156   // $ df /home
157   // Filesystem   512-blocks       Used      Avail %Cap Mounted on
158   // /dev/cgd0a     39711132   37140376     585200  98% /home
159 
160   QStringList mountInfo = LUtils::getCmdOutput("df \"" + dir+"\"");
161   QString::SectionFlag skipEmpty = QString::SectionSkipEmpty;
162   //we take the 5th word on the 2 line
163   QString capacity = mountInfo[1].section(" ",4,4, skipEmpty);
164   return capacity;
165 }
166 
CPUTemperatures()167 QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example)
168   return QStringList(); //not implemented yet
169 }
170 
CPUUsagePercent()171 int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors)
172   return -1; //not implemented yet
173 }
174 
MemoryUsagePercent()175 int LOS::MemoryUsagePercent(){
176   return -1; //not implemented yet
177 }
178 
DiskUsage()179 QStringList LOS::DiskUsage(){ //Returns: List of current read/write stats for each device
180   return QStringList(); //not implemented yet
181 }
182 #endif
183