duminică, 19 decembrie 2021

Ubuntu 20.04 - A few things to do

1) Connect to VPN

In order for a VPN PPTP connection to work, you must do the following:

1) Edit /etc/ufw/before.rules

2) Add the following lines before segment # drop INVALID packets …
# gre
-A ufw-before-input -p 47 -j ACCEPT
-A ufw-before-output -p 47 -j ACCEPT

3) Save file

4) Restart ufw:
sudo ufw disable
sudo ufw enable

Now, a VPN client can be created from Network menu

joi, 6 decembrie 2018

Kubuntu 18.04 Remote Desktop Connection - from Windows and Linux

(1) Xrdp Server

Just type:
sudo apt install xrdp
sudo systemctl enable xrdp

Then you can use Windows Remote Desktop or Remmina on Linux to connect to your system
If you want acces from internet, open/route port 3389


(2) Google Chrome Remote Desktop Connection

Well, not much to be said here: you need Chrome, then just follow the wizards. The best part is that if associate it with your Google Account, you can easy use it across all your devices that support Chrome, and there is also a application for Android

In Windows it works out of the box. In Linux, however, there might be some things to do:

- You must add your user to group "chrome-remote-desktop"
- You must create a folder with the following command (apparently it's a bug and that's the sollution):
        mkdir ~/.config/chrome-remote-desktop
- It might not work with Ubuntu Unity, so I installed lxde
    sudo apt-get install lxde

After installation and configuration restart the system

luni, 22 octombrie 2018

Kubuntu 18.04 / KDE 5.12.6 - A few thoughts and things to do

[This post is a work in progress. I will add things until I change Linux version/distribution. Again]


1) KDE Desktop crashes when changing virtual destops. 
Apparently, the solution is to open System Setting > Desktop Behavior > Virtual Desktops > Switching and disable "Desktop Switching On-screes Display"

2) System enters stabdby on startup if the laptop lead is closed
I had that problem on OpenSuSE some yars ago. I thought it was solved years ago.
Edit the file /etc/systemd/login.conf and make sure you have the following uncommented lines:
HandleLidSwitch=ignore
HandleLidSwitchDocked=ignore

3) BlueTooth is always on by default
We SHOULD BE able to change the default value from BlueTooth interface. Well, in 2018, after so many years of developing operating systems, we are not. For me it's not working, but some said that the following worked:

Edit the file /etc/bluetooth/main.conf and make sure you have one of the following uncommented lines:
AutoEnable=false
InitiallyPowered = false

4) Prevent FPC/Lazarus from automatic updates
...Because it will be a mess.
sudo apt-mark hold fpc
sudo apt-mark hold fpc-src
sudo apt-mark hold lazarus



5) Speed up boot time
I managed to speed up boot time by doing the following:

a) Reduce the log history by limiting it to 5 days (not sure it is a good idea)
sudo journalctl --vacuum-time=5d

b) Delay the apt-daily.service which shouldn't run at startup. So...
sudo systemctl edit apt-daily.timer
...then paste this and save:
# apt-daily timer configuration override
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
AccuracySec=1h
RandomizedDelaySec=30min

Source: https://askubuntu.com/questions/800479/ubuntu-16-04-slow-boot-apt-daily-service


miercuri, 17 octombrie 2018

Lazarus/FPC/ compile from Kubuntu 18.04 (64) to Linux 32, Windows 64 , Windows 32

I have a Linux Kubuntu 18.04 64 bit version.

Compile to Linux 32

1)  sudo apt-get install libc6-dev-i386
   sudo apt-get install g++-7-multilib
   sudo apt-get install gcc-multilib

2) Create a text file on Desktop and name it script.sh (for example)
    Open the file with a text editor (Kate for example) and add the following text:

#!/bin/bash

# Create /usr/bin/i386-linux-ld
cat >/usr/bin/i386-linux-ld << EOF
#!/bin/bash
ld -A elf32-i386 $@
EOF
chmod +x /usr/bin/i386-linux-ld

# Create /usr/bin/i386-linux-as
cat >/usr/bin/i386-linux-as << EOF
#!/bin/bash
as --32 $@
EOF
chmod +x /usr/bin/i386-linux-as


   Save the file and close the editor.
   Right-click on file, ghive it all permissions and mark it as executable.
   Run the file.
   Run the following commands:
which i386-linux-ld
which i386-linux-as
   If they return the location of the files, then the script was successful

3) Run the following commands:
cd /usr/share/fpcsrc/<version> (in my case: cd /usr/share/fpcsrc/3.0.4)
sudo make all CPU_TARGET=i386
sudo make crossinstall CPU_TARGET=i386
sudo make crossinstall CPU_TARGET=i386 INSTALL_PREFIX=/usr

sudo ln -sf /usr/lib/fpc/<version>/ppcross386 /usr/bin/ppcross386
   Locate the file /etc/fpc.cfg end open it with a text editor (like Kate).
   Locate the following lines:
#ifdef cpui386
-Fl/usr/lib/gcc/x86_64-linux-gnu/7
#endif 
  and modify them like this
#ifdef cpui386
-Fl/usr/lib/gcc/x86_64-linux-gnu/7/32
-Fl/usr/lib32
#endif

   Save the file and close

4) create the following links (many thanks: https://tondrej.blogspot.com/2015/05/fpc-and-lazarus-development-environment.html) :

sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
sudo ln -s /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so.0 /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 /usr/lib/i386-linux-gnu/libgobject-2.0.so
sudo ln -s /lib/i386-linux-gnu/libglib-2.0.so.0 /lib/i386-linux-gnu/libglib-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 /usr/lib/i386-linux-gnu/libgthread-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgmodule-2.0.so.0 /usr/lib/i386-linux-gnu/libgmodule-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libpango-1.0.so.0 /usr/lib/i386-linux-gnu/libpango-1.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libcairo.so.2 /usr/lib/i386-linux-gnu/libcairo.so
sudo ln -s /usr/lib/i386-linux-gnu/libpangocairo-1.0.so.0 /usr/lib/i386-linux-gnu/libpangocairo-1.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libatk-1.0.so.0 /usr/lib/i386-linux-gnu/libatk-1.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libglib-2.0.so.0 /usr/lib/i386-linux-gnu/libglib-2.0.so
 
Now it should work!



Compile to Windows 32

Simple and easy

cd /usr/share/fpcsrc/<version> (in my case: cd /usr/share/fpcsrc/3.0.4)
sudo make clean all OS_TARGET=win32 CPU_TARGET=i386
sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr
sudo ln -sf /usr/lib/fpc/<version>/ppcross386 /usr/bin/ppcross386



Compile to Windows 64

Just as simple and easy

cd /usr/share/fpcsrc/<version> (in my case: cd /usr/share/fpcsrc/3.0.4)
sudo make clean all OS_TARGET=win64
sudo make crossinstall OS_TARGET=win64 INSTALL_PREFIX=/usr
sudo ln -sf /usr/lib/fpc/<version>/ppcx64 /usr/bin/ppcx64

It might be necessary to edit the file /etc/fpc.cfg and add the following line:

-Fl/usr/lib/gcc/x86_64-linux-gnu/7


marți, 16 octombrie 2018

Kubuntu 18.04 - running 32 bit program on 64 bit system

In order to run 32 bit program on a 64 bit system, some packages are required. For me, the following commands did the job:
  sudo dpkg --add-architecture i386
  sudo apt-get update
  sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
  sudo apt-get install libgtk2.0-0:i386
  sudo apt-get install gnome-themes-extra gnome-themes-extra:i386

When installing a i386 package, if it announce you that it must remove some packages because they are no longer required, you should be careful: it might actually remove 64 bit packages and you will get a broken system. 

vineri, 29 decembrie 2017

Mint 18.2 / KDE Connect - firewall and writing permission

     In order for KDE Connect to work, the appropriate ports in Mint firewall must be opened. The simplest way to do it is trough command line like this:
     sudo ufw allow 1714:1764/udp
     sudo ufw allow 1714:1764/tcp
     sudo ufw reload
  

     Another problem with KDE Connect was an error about writing to file  /home/neklar/.local/share/user-places.xbel
Solution:
1. open Dolphin as root (sudo dolphin) and go to specified folder
2. right-click on files, Properties
3. in Permission section give to "Others" permission to read and write
4. click OK


sâmbătă, 21 octombrie 2017

From OpenSuSE 32 bits to Mint 64 bits: The Problems of Idealism

From 32 bits to 64 bits: the theory
After 8 (eight) years I decided that it is time to change my good old laptop. Not because it was not working anymore, but because it was just too old. So, I bought a new i5 with 4 GB RAM, 1 TB HDD and nVidia GeForce 940MX video card. 
Everybody is saying: 32 bits is dead, has no future, so switch to 64 bits as soon as possible. I keep hearing this for some years... So if I have a new system, let's install a 64 bits OS. And since OpenSuSE no longer came in 32 bits version and because I'm using it since 2011, the new SuSE Leap was the obvious choice...

From SuSE to Mint
I really don't know what's the problem with SuSE Leap. I'd prefer a longer release cycle in order to have a more trustworthy system. I knew that there will be some issues, but I never expected not to be able to install the nVidia drivers so that the system can work acceptable.
I started to install SuSE Leap... everything was fine. The video card started with the "nouveu" drivers, as expected... So I installed the proprietary nVidia ones. But the video card just didn't work. I tried everything I knew... I made another clean installation.. then another and then another. I read everything I could find on forums, blogs or articles. After 3 days and some 10 clean installations, I decided to try another distribution, because I was beginning to suspect that my new laptop might have an issue...
So, I downloaded Mint 64 (for a moment I even considered Windows), I installed it, and the first thing it asked me (after installation) was that if I want to use the proprietary nVidia drivers. I said yes, it installed something, asked for reboot, and... everything was just working! 3 days of failures were solved in less than one hour.
The reason I chose SuSE back in 2011 was that I liked that distribution: it was secure, reliable, faster than the popular Ubuntu (at least on m computer), "made in Europe" and I really loved YaST (I still do, it's superior to anything Mint had to show so far - my opinion, of course). By using it daily, it was my way of supporting it. But... I didn't have more days to spare, so "good bye SuSE". After all, Linux is, by definition, the freedom of choice. I just don't like the fact that I HAD TO change in stead of WANT TO. But that's the problem with idealism...

From 32 bits to 64 bits: the reality
Well, my idealism was about to be forced again. For years I was using Mozilla Firefox, for the same reason: I could choose. So, I chose to support a certain organisation (Mozilla) because Google does not need more support (it has plenty). Everything appeared to be fine, until I tried to play AngryBirds from Facebook. It wasn't working. I started to google for that error, only to find out that it was something about the 64 bits version. So, 32 bits is dead, 64 bits is the future, but the first is working and the other one is not?! Ok, I don' really need AngryBirds. Then I tried to access my Netflix account (I am also a StarTrek fan) and it wasn't working either. That moment I decided to give Chrome a try, to see if it's a Firefox problem, a 64 bit problem or a Linux problem. Like in SuSE case, everithing just vorked in Chrome (AngryBirds, Netflix, even HBO-Go, although I was told that HBO-Go does not work on Linux). Maybe those issues can be fixed; maybe there is a workaround; with no more time to spare, I uninstalled Firefox and made Chrome my default browser.
Another problem is with the 32 bits applications. They have to work. like I said, 32 bit is dead, but for some strange reason, everybody is still using it and most applications are still created for 32 bits OS. I don't know how many packages I had to install in order to get things work... maybe I will write another blog about this, if I can remember everything.
Then came my real problem and test: how many issues will I have with Lazarus on a 64 bits OS? Will I be able to compile my projects? In short? yes, but in another 3 days of try, error and search.

Ready to work. Really?
I installed Lazarus for Debian with very little problems, except for the software management of Mint (did I say that I miss YaST?). No problem, I'm starting to know how to use "apt-get install". I knew that there will be issues with the "integer" type, but again I had problems finding the documentation for 64 bits... everybody is writhing about the dead 32 bits version, with little reference to what might happen if you try to compile for 64 bits. My people has a saying with the following approximate translation: "about the dead ones we will say only good things".
So, I have to compile in Lazarus for 32 bit systems, both Linux and Windows. It took me about 3 days to figure it out and that's another story...

luni, 10 iulie 2017

OpenSuSE 13.2 file limit / Too many files opened error

After having some trouble with "too many files opened" error, I made some research and I found out that Linux has by default some limits concerning maximum number of files that a user can open. Fortunately, we can change that.

First let's see how many files can we open. So, in a terminal type
     ulimit -n
It will return the number of files. Default is 1024.

To change that limit, do the following:

1) Open Dolphin as root

2) Go to  /etc/security/ and open file limits.conf

3) At the end of the file add the following:

*               soft    nofile            4096
*               hard    nofile            10240

4) Save and restart.

5) Open a terminal and type ulimit -n again. It should return 4096.

Observations:
- This will increase the number of files for all users. If you want to modify those values for only one user, it is possible, but I didn't try. Basically, you should replace the * character at the beginning of the line with the username (?)
- Do not omit the * character at the beginning of the line. it means "all users". A line must have 4 parameters, * being the first.
- The values I used are those recommended on different forums. I can't offer an explanation for them.

joi, 16 februarie 2017

Lazarus / FPC / OpenSuSE 13.2 - Problems with "Backspace" and "Delete"

     I noticed recently that when I try to delete a character in a TEdit box, the "Backspace" and "Delete" keys are not acting the right way. More specifically, after deleting the required character, the cursor was jumping to the right. Only on Linux, no problems on Windows
     After a lot of search and with support from Lazarus/FPC community, here is the solution:

1) Open Dolphin as root

2) Edit the file /usr/lib/lazarus/lcl/interfaces/gtk2/gtk2callback.inc and modify the line 604 like this:
     // if (gtk_major_version = 2) and (gtk_minor_version < 17) then

3) Edit the file /usr/lib/lazarus/lcl/interfaces/gtk2/gtk2widgetset.inc and modify the line 465 like this:
     // if (gtk_major_version = 2) and (gtk_minor_version < 17) then

     Basically, you have to "comment" those lines so that they are not executed anymore

4) Rebuild Lazarus (open Lazarus, go to "Tools" and select "Build Lazarus")

Done!

     Here is the original bug report on Lazarus official page:

vineri, 6 ianuarie 2017

OpenSuSE 13.2 / TeamViewer "not ready", "connection error"

After some years of using teamViewer with no problems, yesterday, out of the blue, it started to give a "connection error". Reboot didn't work, but the solution is, actualy, a restart of TeamViewer. So, just open a terminal and type:
    sudo teamviewer daemon stop
    sudo teamviewer daemon start

joi, 29 septembrie 2016

OpenSuSE 13.2 - connect to Windows Remote Desktop

     In order to remotely connect to a Windows Server 2012, I have tested 2 programs: KRDC and Remmina. Both works quite fine, with a plus for Remmina, which allows printer sharing. Let's take a look at them.

KRDC
     KRDC is made by KDE and I found it installed by default. At least, I don't remember installing it by myself. It does not require anything special, it just works, even on a slower connection. It is easy to configure. It has a "Media sharing" option which I couldn't figure out what it does. It does not has a "Printer sharing" option and I couldn't find a "File sharing" option. Maybe the "Media sharing" option can be used, but I don't know how.
     In short, for a simple remote control it's just what you need, especially on a KDE desktop.

Remmina Remote Desktop
     Remmina is more sophisticated. It can be easily installed through Yast: just open and search for Remmina. Pay attention, you must also install remmina-plugin-rdp in order to connect to a Windows Remote Desktop.
     Once installed, it is about just as easy to configure and use as KRDC. Subjectively speaking, I think it requires a fastest connection connection. However, it has "File sharing" and "Printer sharing". In a very strange way, printer sharing will work only if you enable the "Sound" option as "Local". Concerning printer, in my case it didn't print the whole page no matter what setting I tried: the first 3 lines were just missing. I don't know it it was a driver-problem on Linux side or a Remmina-problem.
     "File sharing" is working fine. Just select a folder in configuration options and it will appear as a virtual drive on Windows side. No problems.

My conclusion:
     Remmina is more complete. However, if you need to rely on it for printing, make sure you test it.

[UPDATE]
     For some strange reason, this morning Remmina refused to connect to server, saying "Unable to connect" The solution was to delete the file /home/neklar/.freerdp/known_hosts

duminică, 25 septembrie 2016

OpenSuSE 13.2 / ACER laptop - system goes to sleep

     I have a ACER laptop for quite some time (2009). Most of the time I use it as a desktop computer: the lid is closed and the image goes to a  external monitor. Of course, I disabled the lid-event in order to prevent the system to go to sleep. I never had any problems with that.
     However, this morning, after applying some updates, the system started to behave differently: it was going to sleep every 20 seconds or so, without any obvious reason. I checked all the settings and everything appeared to be normal. If I opened the lid, it was not going to sleep anymore, but when I closed it back, the same problem returned. Ok, I can stay with the lid open, but I don't like it that way.
     So, I have some possibilities:
          1) the system is too old and it's showing its age
          2) there is a new setting after the update and I cannot found it
          3) there is a bug in the update (either a driver or a setting)
     I don't have an answer, but after google-ing a while I have a solution (or, at least, a workaround): I forced the system to ignore the lid.

1) Open Dolphin a SuperUser (you need root access)
2) Edit the file /etc/systemd/logind.conf
3) Add (or modify if it already exists) the following line: HandleLidSwitch=ignore (also make shure it does not have the # character in front of it; this character marks a line as comment and it will be ignored)
4) Save and reboot

luni, 29 februarie 2016

DropBox / OpenSuSE 13.2 / SysTry icon=?

For some strange reason, DropBox icon does not appear in SysTry on OpenSuSE 13.2. I couldn't find a solution or a workaround, so... I designed my own application.
Here it is:
https://www.dropbox.com/sh/if0g7xwgcksdow5/AACREupcxQh_1pYy7JYHwIRDa?dl=0

In Lazarus/FPC, of course.
OK, it's not a complete app: it just reads the status of the Dropbox an changes the color of the SysTry icon, but that's good enough for me

duminică, 22 noiembrie 2015

Games on OpenSuSE

Here are some games and some issues I came across

Jedi Academy
There is a port for Linux of Jedi Academy. However, I have the old Windows versions and it runs excellent in Wine, once you can make it work. So, here are the steps:
1) Make sure that your CD-Rom is configured correctly in Wine. Open WineCfg
2) Install the game (should not be any problems)If the game stacks when you should change the CDs, do the following:
   a) Create an ISO image for each CD an put it somewhere where you can find it (I created a directory in Documents
   b) Create 2 directories (ISO1 andI SO2) and then 2 virtual devices (one for each image) like this:

sudo mount -o loop /home/neklar/Documents/JediAcademy/jediAcdCD1.iso /home/neklar/Documents/Jocuri/JediAcademy/ISO1

sudo mount -o loop /home/neklar/Documents/JediAcademy/jediAcdCD2.iso /home/neklar/Documents/JediAcademy/ISO2

  c) Open WineCfg again and mount those 2 devices. go to advanced properties and specify that they are CD-ROMs
   d) Install the game
3) The Game's executables are jamp.exe (multiplayer) and jasp.exe (single player). You must locate them, because they have to be modified. Typically, they should be in Wine directory, like mine: /home/neklar/.wine/drive_c/Program Files/LucasArts/Star Wars Jedi Knight Jedi Academy/GameData/
4) A good editor to do the trick is Okteta. If you don't have it, install it (package okteta)
5) With Okteta, open the file jamp.exe. Locate the expression GL_EXTENSIONS %s , replace 's' with 'p' (should look like this: GL_EXTENSIONS %p ) then save. Do the same for jasp.exe. Start the game from one of those files (single player or multiplayer) and have fun!
For me, it works on maximum resolution and with all details, both single and multiplayer
Pay attention: There is a noCD pach (or crack ?!) for it, but it will not work with that.

sâmbătă, 7 noiembrie 2015

OpenSuSE 13.2 / Dell Inspiron 1501 / Broadcom B43 wireless solution

I've installed OpenSuSE 13.2 on a older Dell Inspiron 1501 laptop. Everithing was fine, except for the wireless card which refused to work. After searching the internet I found out that the problem was the B34 driver. So, here is my solution:

1) Make sure that the b43-fwcutter package is installed. Open Software Management, search for it and install it if it's not

2) Open Dolphin as SuperUser and find /usr/sbin/install_bcm43xx_firmware
Right click on it and select Actions>Run in Konsole (so that you can see the output).

3) Reboot.

marți, 29 septembrie 2015

OpenSuSE 13.2 / Snapper / free space on ROOT

     I installed OpenSuSE 13.2 a while ago (about 5 months) and I noticed that the used space on ROOT was growing steadily. I ignored the issue until yesterday, when the free space on root was only 760 MB (from a total of 20GB).
     After searching the internet for a while, I concluded that "Snapper" was responsible for that situation.
     As far as I can tell, Snapper is a backup system, so it creates periodically "snapshots" that can be used for recovery. Since I never used it in about 3 years of LINUX, I decided that I don't need this application, and I removed it. Result? About 9 (nine) GB free on rood and a visibly faster system. I admit though that my system is no longer a "modern" one, but it's doing its job: Acer Core 2 Duo 2200 MHz, 3GB RAM, 300GB HDD.
     If you decide to remove the Snapper, the files created for recovery must also be removed, otherwise you accomplished nothing (except the fact that it will stop growing). So, before you uninstall, you must start Snapper from your program list and there you will find all of the backup files ever created, so you can delete them

luni, 21 septembrie 2015

Lazarus / FPC: sort a StringGrid

Here it is, a nice simple procedure that sorts a StringGrid. Tested an a 5000 records StringGrid, the sorting is done in about 1-2 seconds
   sg: your stringgrid
   col: column that will be sorted
   numeric: if the values in column are numbers
   asc: ascendent or descendent
   numeric: if datas are numbers

procedure sort(sg:tstringgrid;col:integer;asc:boolean=true;numeric:boolean);
var i,c:integer; numeric:boolean; f:string; r:real; negat:boolean; x1:integer; semn,s1,s2:string;
begin
  numeric:=false;
  negat:=false;


  if asc=true then sg.SortOrder:=soascending else sg.SortOrder:=sodescending;

  if numeric=false then
     sg.SortColRow(true, col, sg.FixedRows, sg.RowCount-1)
  else begin
     f:='000000000000000.00';
     c:=sg.colcount;
     sg.ColCount:=c+1;
     for i:=1 to sg.RowCount-1 do
       begin
          try r:=strtofloat(sg.Cells[col,i]) except r:=0 end;
          if r<0 then
            begin
              negat:=true;
              sg.Cells[c,i]:='-'+formatfloat(f,r);
            end else sg.Cells[c,i]:='+'+formatfloat(f,r);
       end;
     sg.SortColRow(true, c, sg.FixedRows, sg.RowCount-1);
     if negat=true then
       begin
          x1:=0;
          semn:=sg.Cells[c,0][1];
          s1:=semn; s2:=' ';
          for i:=0 to sg.RowCount-1 do
            if sg.Cells[c,0][1]<>semn then
              begin
                semn:=sg.Cells[c,0][1];
                s2:=semn;
                x1:=i;
              end;
          if s1='-' then
            begin
               if sg.SortOrder=soascending then sg.SortOrder:=sodescending else sg.SortOrder:=soascending;
               sg.SortColRow(true, c, sg.FixedRows, x1-1);
            end;
          if s2='-' then
            begin
               if sg.SortOrder=soascending then sg.SortOrder:=sodescending else sg.SortOrder:=soascending;
               sg.SortColRow(true, c, x1, sg.RowCount-1);
            end;
       end;
     sg.ColCount:=c;
  end;
end;

duminică, 20 septembrie 2015

OpenSuSE 13.2 / Quickview plasmoid

After switching to OpenSuSE 13.2 I found that a certain plasmoid is no longer available - Quickview. Finally, I found the sources and I managed to install it on my system. I also uploaded it here:


Download the archive somewhere where you can use it (Documents, for example) and unpack it (right click > Extract here). You will find a "readme " file with full instructions of how to build and install the plasmoid. Be careful about the required extra packages (kdelibs, libxonq, - devel packages and gettext package) and don't forget to restart the system. The file also contain proper credit for those who created this plasmoid - I have no contribution

luni, 6 iulie 2015

Lazarus / FPC - run a command and read it's output, working with system tray; laptop's battery on OpenSuSE 12.x - 13.1

     For unknown reasons, KDE on OpenSuSE 12.x and 13.1 (so far) does not recognize correctly the battery of my Acer laptop. It says “Battery not present”, wich is not true. After some unsuccessful attempts to fix this, I gave up and decided to write my own program. 

     In order for my program to work, it must:
1) Run a LINUX command line to obtain the battery statistics and load the output
2) Analyse the output an identify the values that are needed
3) Create a simple interface to display the results
4) Minimise the main form to system tray (and then maximise if needed)
5) Change the system tray icon to display the level of the battery for quick view and artistic impression :-)

You need:
- a form
- a memo
- 2 buttons
- a ImageList from Common Controls
- a timer
- a TrayIcon from Additional

Doubleclick on ImageList to load the images you like for different battery states (I created my own, size 16x32)

The full program can be downloaded from here

If you are not interested in the source code, you need only the file BatteryF

Here is the full code

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Buttons, Process, strutils;

type

  { TForm1 }

  TForm1 = class(TForm)
    ImageList1: TImageList;
    Memo1: TMemo;
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Timer1: TTimer;
    TrayIcon1: TTrayIcon;
    procedure FormShow(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure TrayIcon1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  Bmp: tbitmap;
  Bat: integer;

function get1:tstringlist;

implementation

{$R *.lfm}

{ TForm1 }

function get1:tstringlist;
var l:tstringlist; Proc1: tprocess; t1,t2:string; i,j,k:integer;
begin
   bmp :=tbitmap.Create;
   form1.Memo1.Lines.Clear;

   /// run a command line and read the output
   /// first we must determine if a battery is present or detected

   l:=tstringlist.Create;
   proc1:=tprocess.Create(form1);

   proc1.Executable:='upower';
   proc1.Parameters.Add('-e');

   proc1.Options := proc1.Options + [poWaitOnExit, poUsePipes];
   proc1.Execute;
   l.LoadFromStream(proc1.Output);    /// load the output to stringlist
   t1:='';
   for i:=0 to l.Count-1 do
   begin
     t2:=l[i];
     if AnsiContainsText(t2,'BAT') then t1:=t2;  /// BAT is for battery
   end;

/// if a battery is detected
  if t1<>'' then
   begin
     form1.trayicon1.Hint:='';
     proc1.Parameters.Clear;
     proc1.Parameters.Add('-i');  /// for more details see upower documentation
     proc1.Parameters.Add(t1);
     proc1.Execute;
     l.LoadFromStream(proc1.Output);

     for i:=0 to l.Count-1 do
     begin
       t2:=l[i];
       if AnsiContainsText(t2,'percentage') then      /// find the battery level
        begin
          j:=length(t2);
          bat:=strtoint(midstr(t2,j-3,3));
          form1.Caption:='Battery level: '+inttostr(bat)+'%';
          form1.trayicon1.Hint:=form1.trayicon1.Hint+t2+chr(13);
        end;
       if AnsiContainsText(t2,'time to empty') then
            form1.trayicon1.Hint:=form1.trayicon1.Hint+t2+chr(13);
     end;
/// "form caption" and "trayicon hint" are for artistic impression :-)
/// if upower displays the results in a different language (I don't know if it can),
    // the program will find nothing when searching for "percentage" and "time to empty"
    // so you must modify the keyword acording to your language
   k:=0;
   if bat>20 then k:=1; /// select the image number from timagelist for system tray
   if bat>35 then k:=2;
   if bat>50 then k:=3;
   if bat>70 then k:=4;
   if bat>90 then k:=5;
   if bat=100 then k:=7;

   form1.imagelist1.GetBitmap(k,bmp);   /// get the image from timagelist
   form1.trayicon1.Icon.assign(bmp);    /// assign the image to system tray

   end

  else
      begin
        l.Add('Battery not detected or not present');
        form1.imagelist1.GetBitmap(6,bmp);
        form1.trayicon1.Icon.assign(bmp);
      end;

   proc1.Free;
   bmp.Free;
   result:=l;

end;

procedure TForm1.FormShow(Sender: TObject);
begin
    memo1.Text:=get1.Text;   /// display the full statistics
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  form1.close;    /// terminate the program
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  form1.Hide;     /// minimise to system tray
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   memo1.Text:=get1.Text;   /// refresh the status every 60 seconds
end;

procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
  form1.Show;      /// show the main form when click on tray icon
end;

end.
 
 

vineri, 17 aprilie 2015

Raspberry Pi - A (very) simple GUI for OMXPlayer

I have created a simple GUI for OMXPlayer on Raspberry Pi

It can be downloaded from here:

https://www.dropbox.com/sh/d5bw7h3j33vmu5t/AAARZeUlm4pvHHJwnqUEn4Jqa?dl=0

The only needed file is omxGUI, but I also uploaded the sources (written, of course, in Pascal)