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 __FreeBSD_kernel__
8 #ifndef __FreeBSD__
9 // The above two checks should make sure that we are on a
10 // operating system using the FreeBSD kernel without actually being
11 // on FreeBSD. That probably means Debian's kFreeBSD port.
12 #include <QDebug>
13 #include "LuminaOS.h"
14 #include <unistd.h>
15 #include <stdio.h> // Needed for BUFSIZ
16 
17 //can't read xbrightness settings - assume invalid until set
18 static int screenbrightness = -1;
19 
OSName()20 QString LOS::OSName(){ return "Debian GNU/kFreeBSD"; }
21 
22 //OS-specific prefix(s)
23 // NOTE: PREFIX, L_ETCDIR, L_SHAREDIR are defined in the OS-detect.pri project file and passed in
LuminaShare()24 QString LOS::LuminaShare(){ return (L_SHAREDIR+"/lumina-desktop/"); } //Install dir for Lumina share files
AppPrefix()25 QString LOS::AppPrefix(){ return "/usr/"; } //Prefix for applications
SysPrefix()26 QString LOS::SysPrefix(){ return "/usr/"; } //Prefix for system
27 
28 //OS-specific application shortcuts (*.desktop files)
ControlPanelShortcut()29 QString LOS::ControlPanelShortcut(){ return ""; } //system control panel
AppStoreShortcut()30 QString LOS::AppStoreShortcut(){ return ""; } //graphical app/pkg manager
31 //OS-specific RSS feeds (Format: QStringList[ <name>::::<url> ]; )
RSSFeeds()32 QStringList LOS::RSSFeeds(){ return QStringList(); }
33 
34 // ==== ExternalDevicePaths() ====
ExternalDevicePaths()35 QStringList LOS::ExternalDevicePaths(){
36     //Returns: QStringList[<type>::::<filesystem>::::<path>]
37       //Note: <type> = [USB, HDRIVE, DVD, SDCARD, UNKNOWN]
38    QStringList devs = LUtils::getCmdOutput("mount");
39   //Now check the output
40   for(int i=0; i<devs.length(); i++){
41     if(devs[i].startsWith("/dev/")){
42       QString type = devs[i].section(" on ",0,0);
43         type.remove("/dev/");
44       //Determine the type of hardware device based on the dev node
45       if(type.startsWith("da")){ type = "USB"; }
46       else if(type.startsWith("ada")){ type = "HDRIVE"; }
47       else if(type.startsWith("mmsd")){ type = "SDCARD"; }
48       else if(type.startsWith("cd")||type.startsWith("acd")){ type="DVD"; }
49       else{ type = "UNKNOWN"; }
50       //Now put the device in the proper output format
51       devs[i] = type+"::::"+devs[i].section("(",1,1).section(",",0,0)+"::::"+devs[i].section(" on ",1,50).section("(",0,0).simplified();
52     }else{
53       //invalid device - remove it from the list
54       devs.removeAt(i);
55       i--;
56     }
57   }
58   return devs;
59 }
60 
61 //Read screen brightness information
ScreenBrightness()62 int LOS::ScreenBrightness(){
63    //Returns: Screen Brightness as a percentage (0-100, with -1 for errors)
64   if(screenbrightness==-1){
65     if(QFile::exists(QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/.currentxbrightness")){
66       int val = LUtils::readFile(QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/.currentxbrightness").join("").simplified().toInt();
67       screenbrightness = val;
68     }
69   }
70   return screenbrightness;
71 
72 }
73 
74 //Set screen brightness
setScreenBrightness(int percent)75 void LOS::setScreenBrightness(int percent){
76   //ensure bounds
77   if(percent<0){percent=0;}
78   else if(percent>100){ percent=100; }
79   // float pf = percent/100.0; //convert to a decimel
80   //Run the command
81   QString cmd = "xbacklight -set %1";
82   // cmd = cmd.arg( QString::number( int(65535*pf) ) );
83   cmd = cmd.arg( QString::number( percent ) );
84   int ret = LUtils::runCmd(cmd);
85   //Save the result for later
86   if(ret!=0){ screenbrightness = -1; }
87   else{ screenbrightness = percent; }
88   LUtils::writeFile(QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/.currentxbrightness", QStringList() << QString::number(screenbrightness), true);
89 
90 }
91 
92 //Read the current volume
audioVolume()93 int LOS::audioVolume(){ //Returns: audio volume as a percentage (0-100, with -1 for errors)
94    return -1;    // not available on kFreeBSD yet
95 }
96 
97 //Set the current volume
setAudioVolume(int)98 void LOS::setAudioVolume(int){ //percent: 0-100
99    return;
100 }
101 
102 //Change the current volume a set amount (+ or -)
changeAudioVolume(int percentdiff)103 void LOS::changeAudioVolume(int percentdiff){
104   int old_volume = audioVolume();
105   int new_volume = old_volume + percentdiff;
106   if (new_volume < 0)
107       new_volume = 0;
108   if (new_volume > 100)
109       new_volume = 100;
110   qDebug() << "Setting new volume to: " << new_volume;
111   setAudioVolume(new_volume);
112 }
113 
114 //Check if a graphical audio mixer is installed
hasMixerUtility()115 bool LOS::hasMixerUtility(){
116   return QFile::exists("/usr/bin/pavucontrol");
117 }
118 
119 //Launch the graphical audio mixer utility
startMixerUtility()120 void LOS::startMixerUtility(){
121   QProcess::startDetached("/usr/bin/pavucontrol");
122 }
123 
124 //Check for user system permission (shutdown/restart)
userHasShutdownAccess()125 bool LOS::userHasShutdownAccess(){
126   return true; //not implemented yet
127 }
128 
129 //Check for whether the system is safe to power off (no updates being perfomed)
systemPerformingUpdates()130 bool LOS::systemPerformingUpdates(){
131   return false; //Not implemented yet
132 }
133 
134 //Return the details of any updates which are waiting to apply on shutdown
systemPendingUpdates()135 QString LOS::systemPendingUpdates(){
136   return "";
137 }
138 
139 //System Shutdown
systemShutdown(bool)140 void LOS::systemShutdown(bool){ //start poweroff sequence
141   //INPUT: skip updates (true/false)
142   QProcess::startDetached("shutdown -h now");
143 }
144 
145 //System Restart
systemRestart(bool)146 void LOS::systemRestart(bool){ //start reboot sequence
147   //INPUT: skip updates (true/false)
148   QProcess::startDetached("shutdown -r now");
149 }
150 
151 //Check for suspend support
systemCanSuspend()152 bool LOS::systemCanSuspend(){
153   return false;
154 }
155 
156 //Put the system into the suspend state
systemSuspend()157 void LOS::systemSuspend(){
158 
159 }
160 
161 //Battery Availability
hasBattery()162 bool LOS::hasBattery(){
163   return false;
164 }
165 
166 //Battery Charge Level
batteryCharge()167 int LOS::batteryCharge(){ //Returns: percent charge (0-100), anything outside that range is counted as an error
168   return -1;
169 }
170 
171 //Battery Charging State
batteryIsCharging()172 bool LOS::batteryIsCharging(){
173   return false;
174 }
175 
176 //Battery Time Remaining
batterySecondsLeft()177 int LOS::batterySecondsLeft(){ //Returns: estimated number of seconds remaining
178   return 0; //not implemented yet for Linux
179 }
180 
181 //File Checksums
Checksums(QStringList)182 QStringList LOS::Checksums(QStringList){ //Return: checksum of the input file
183  return QStringList();
184 }
185 
186 //file system capacity
FileSystemCapacity(QString)187 QString LOS::FileSystemCapacity(QString) { //Return: percentage capacity as give by the df command
188   return QString();
189 }
190 
CPUTemperatures()191 QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example)
192   return QStringList(); //not implemented yet
193 }
194 
CPUUsagePercent()195 int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors)
196   return -1; //not implemented yet
197 }
198 
MemoryUsagePercent()199 int LOS::MemoryUsagePercent(){
200   return -1; //not implemented yet
201 }
202 
DiskUsage()203 QStringList LOS::DiskUsage(){ //Returns: List of current read/write stats for each device
204   return QStringList(); //not implemented yet
205 }
206 #endif
207