Active Topics

 


Reply
Thread Tools
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#1
here is a perl script that i run from my computer with sync-and-connect on that sets my launcher icons from an easy-to-configure script instead of fussing about with it on the phone.

the names are the NAME in files like /usr/share/applications/NAME.desktop

Code:
#!/usr/bin/perl
use strict;
use warnings;

my $host = "192.168.2.15";
chomp $host;

my @config = qw(
  call-history
  messaging-ui
  meego-terminal
  fennec 

  pidgin
  klomp
  camera-ui
  duicontrolpanel

  nokia-drive-qml
  xmcr
  vmpkn9
  FBReader
  
  clock
  dir-stuff[
    gallery
    video-suite
    calendar
    notes
    ]
  dir-box[
    maps
    calc
    accountsui
    gconfik_harmattan
    ]
  dir-bluetooth[
    btinput-terminal
    btinput_harmattan
    toggleBT_harmattan
    ]
 
  contacts
  mail
  joikuspot
);

my @quickLaunch = qw(
  call-history
  messaging-ui
  fennec 
  camera-ui
);


my %apps;
my %appDirs;
my %dirs;
my %dirNames;

my $index = 0;
my $nextDir = 1;
for(my $i=0; $i<@config; $i++){
  my $item = $config[$i];
  if($item =~ /^dir-(.*)\[$/){
    my $dirName = $1;
    $dirs{$nextDir} = $index++;
    $dirNames{$nextDir} = $dirName;

    my $dirIndex = 0;
    while(++$i<@config and $config[$i] ne ']'){
      my $app = $config[$i];
      $appDirs{$app} = $nextDir;
      $apps{$app} = $dirIndex++;
    }

    $nextDir++;
  }else{
    my $app = $config[$i];
    $apps{$app} = $index++;
  }
}

my $appDir = '/usr/share/applications';
my $unusedDir = '/opt/unused-applications';
my $directoryDir = '/home/user/.local/share/applications';
my $quickLaunchDir = '/home/user/.local/share/applications';
my $confFileDest = '/home/user/.config/meegotouchhome-nokia/launcherbuttons.data';

sub launcherPath($);
sub createAppDesktopFiles();
sub createDirDesktopFiles();
sub createQuickLauncherDesktopFiles();
sub getAppData();
sub getDirData();
sub getQuickLauncherData();
sub getData();
sub writeLauncherButtonsData($);

sub main(@){
  die "Usage: $0\n" if @_ > 0;
  createAppDesktopFiles();
  createDirDesktopFiles();
  createQuickLauncherDesktopFiles();
  
  my $data = getData();
  system "ssh root\@$host killall meegotouchhome";
  writeLauncherButtonsData($data);
}


sub launcherPath($){
  my $path = shift;
  $path =~ s/^\///;
  $path =~ s/\//\\/g;
  return $path;
}


sub createAppDesktopFiles(){
  system "ssh", "root\@$host", "
    set -x
    mkdir -p $unusedDir
    cd $appDir
    bash -c 'find -maxdepth 1 -name \\*.desktop -execdir mv {} $unusedDir \\;'
    rm -rf $appDir
    mkdir -p $appDir
  ";

  my $cmd = "cd $unusedDir\n";
  for my $app(keys %apps){
    $cmd .= "mv $app.desktop $appDir\n";
  }
  print $cmd;
  system "ssh", "root\@$host", $cmd;
}

sub createDirDesktopFiles(){
  system "ssh", "root\@$host", "rm $directoryDir/*.directory";
  for my $dir(sort keys %dirs){
    my $dirName = $dirNames{$dir};
    my $content = ''
      . "[Desktop Entry]\n"
      . "Type=Directory\n"
      . "Name=$dirName\n"
      . "X-MeeGo-Folder-Index=$dir\n"
      . "Icon=icon-l-default-application\n"
      . "OnlyShowIn=X-MeeGo;\n"
      ;
    my $tmpFile = "/tmp/meego-dir";
    open FH, "> $tmpFile" or die "Couldnt write to $tmpFile\n";
    print FH $content;
    close FH;
    my $fileName = "$directoryDir/folder$dir.directory";
    system "scp", $tmpFile, "root\@$host:$fileName";
  }
  system "ssh", "root\@$host", "chown user.users -R $directoryDir";
}

sub createQuickLauncherDesktopFiles(){
  my $cmd = "rm $quickLaunchDir/*.desktop\n";
  for(my $i=0; $i<@quickLaunch; $i++){
    my $qlFile = "$quickLaunchDir/quicklaunchbar$i.desktop";
    $cmd .= "ln -s $appDir/$quickLaunch[$i].desktop $qlFile;\n";
  }
  $cmd .= "chown user.users -R $quickLaunchDir\n";
  print $cmd;
  system "ssh", "root\@$host", $cmd;
}



sub getAppData(){
  my $data = '';
  for my $app(sort keys %apps){
    my $index = $apps{$app};
    my $dir = $appDirs{$app};
    $dir = 0 if not defined $dir;
    
    my $desktopFile = "$appDir/$app.desktop";
    $data .= launcherPath($desktopFile) . "=launcher/$dir/$index\n";
  }
  return $data;
}

sub getDirData(){
  my $data = '';
  for my $dir(sort keys %dirs){
    my $dirName = $dirNames{$dir};
    my $index = $dirs{$dir};
    my $desktopFile = "$directoryDir/folder$dir.directory";
    $data .= launcherPath($desktopFile) . "=launcher/0/$index\n";
  }
  return $data;
}

sub getQuickLauncherData(){
  my $data = '';
  for(my $i=0; $i<@quickLaunch; $i++){
    my $desktopFile = "$quickLaunchDir/quicklaunchbar$i.desktop";
    $data .= launcherPath($desktopFile) . "=quicklaunchbar/$i\n";
  }
  return $data;
}

sub getData(){
  my $data = "[DesktopEntries]\n";
  $data .= getDirData();
  $data .= getQuickLauncherData();
  $data .= getAppData();
  return $data;
}

sub writeLauncherButtonsData($){
  my $data = shift;
  print $data;

  my $tmpFile = "/tmp/launcherbuttons.data";
  open FH, "> $tmpFile" or die "Couldnt write to $tmpFile\n";
  print FH $data;
  close FH;

  system 'scp', $tmpFile, "root\@$host:$confFileDest";
}

&main(@ARGV);
__________________
~ teleshoes ~
 

The Following User Says Thank You to wolke For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 16:40.