#!/bin/bash
#############################################################
#  pclos_docuportal
#
# Purpose: access online man-pages, wiki, forum, etc 
# 
# Requirements: 
#  - PCLinuxOS installation 
#  - Internet connection
#  - zenity
#
# Version: 0.1-7 (2012-09-02) by pinoc <vogtpet@gmail.com>
#############################################################
# Copyright (C) 2012 Bill Reynolds <texstar@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################

# define some variables
#=================================================
WICON='/usr/share/icons/education_literature_section.png' 
TITLE="PCLinuxOS documentation portal"
ZEN2="zenity --window-icon="$WICON

# browser test
#======================
wwwb=""
KSM=`pidof ksmserver`
if [ "${#KSM}" == "0" ];then HAS_KDESESSION="0"; else HAS_KDESESSION="1"; fi

if [ "$HAS_KDESESSION" == "1" ];then
  wwwb="kfmclient exec "
else
  # test on non-KDE: 
  # unfortunately www-browser and xdg-open does not work
  # everywhere so we first test through a list of browsers
  # to find out if there is any browser installed
  for idx in chromium-browser firefox opera midori arora epiphany jumanji xxxterm galeon seamonkey flock iron-browser
  do
    if which $idx 2>/dev/null; then
      wwwb=`which $idx 2>/dev/null`
      break
    fi
  done

  # now try to find out the default browser with xdg-mime
  if [ -e /usr/bin/xdg-mime ];then
    # test if we have any entry in there
    qq=`xdg-mime query default text/html|grep -c .desktop`
    if [ $qq -gt 0 ];then
      qq=`xdg-mime query default text/html`; qq=${qq/.desktop/}
      wwwb=`which $qq 2>/dev/null`
    fi
  fi
fi

# exit if no browser was found
if [ "$wwwb" == "" ];then
  $ZEN2 --title="$TITLE" --width 350 --error --text "Could not detect any webbrowser.\n\nExiting..."
  exit 1
fi

# define titles
#===================
OOLOCT=("PCLinuxOS: General announcements" "PCLinuxOS: SW-announcements" "PCLinuxOS: Twitter" "PCLinuxOS: Forum" "PCLinuxOS: Magazine" "PCLinuxOS: Wiki" "PCLinuxOS: IRC Chat" "PCLinuxOS: System update" "PCLinuxOS: Synaptic" "PCLinuxOS: Gnome" "PCLinuxOS: Homepage" "PCLinuxOS: Email" "PCLinuxOS: Images" "Help Me"  "Newbie: Linuxrsp" "Newbie: LinuxAlternative" "Newbie: Grokdoc" "Docu: command sheet" "Docu: man-pages" "Docu: Linux Rute" "Docu: TLDP" "Docu: DIE" "Docu: Linux in a Nutshell" "Docu: Linuxtopia" "Docu: Linux Questions" "Books: FreeComputerBooks" "Books: OnlineProgBooks" "Tools: YouTube mp3" "Tools: TinyPic")
count=${#OOLOCT[@]}

# corresponding websites
#=========================
OOLOC=("http://www.pclinuxos.com/forum/index.php/board,1.0.html" "http://www.pclinuxos.com/forum/index.php/board,66.0.html" "http://twitter.com/#!/iluvpclinuxos" "http://www.pclinuxos.com/forum/" "http://pclosmag.com/" "http://pclinuxoshelp.com/index.php/Main_Page" "http://webchat.freenode.net/?channels=pclinuxos-support&uio=OT10cnVlJjExPTE5NQ64" "http://www.pclinuxos.com/forum/index.php/topic,63199.0.html" "http://pclinuxoshelp.com/index.php/Synaptic_and_the_Repositories" "http://linuxgator.org/" "http://www.pclinuxos.com/" "https://pclosmail.com/src/login.php" "http://myphotos.mypclinuxos.com/" "http://bit.ly/uiqkuv" "http://www.linuxrsp.ru/win-lin-soft/table-eng.html" "http://www.linuxalt.com/" "http://grokdoc.net/index.php/Application_Crossover_Chart" "http://www.pixelbeat.org/cmdline.html" "http://linuxmanpages.com/" "http://rute.2038bug.com/index.html.gz" "http://www.tldp.org/" "http://linux.die.net/" "http://www.oreillynet.com/linux/cmd/" "http://www.linuxtopia.org/" "http://www.linuxquestions.org/questions/"  "http://freecomputerbooks.com/unixCategory.html" "http://www.onlineprogrammingbooks.com/"
"http://www.youtube-mp3.org/"
"http://tinypic.com")

GOO_LANG="q"
while [ "$GOO_LANG" != "" ]
do

  # Provide options via zenity dialog text
  #=================================================
  GOO_LANG=$($ZEN2 --title "$TITLE" --list --text $"Please select an option from the list below or press <b>Cancel</b> to quit this script." --width 700 --height 500 --radiolist --column $"Select" --column $"Website" --column $"Description" \
   TRUE "PCLinuxOS: General announcements" "Important general announcements" \
  FALSE "PCLinuxOS: SW-announcements" "Important software news" \
  FALSE "PCLinuxOS: Twitter" "Daily tweets by Texstar" \
  FALSE "PCLinuxOS: Forum" "Help and chat with community members" \
  FALSE "PCLinuxOS: Magazine" "Cool articles about PCLinuxOS" \
  FALSE "PCLinuxOS: Wiki" "Read/contribute to the PCLinuxOS Knowledge Base" \
  FALSE "PCLinuxOS: IRC Chat" "Live chat support via IRC" \
  FALSE "PCLinuxOS: System update" "Learn how to properly update your system"  \
  FALSE "PCLinuxOS: Synaptic" "Learn about our software manager" \
  FALSE "PCLinuxOS: Gnome" "Forum for PCLinuxOS-Gnome users" \
  FALSE "PCLinuxOS: Homepage" "Access anything else from here" \
  FALSE "PCLinuxOS: Email" "PCLinuxOS email accounts" \
  FALSE "PCLinuxOS: Images" "MyPCLinuxOS Image Hosting" \
  FALSE "Help Me" "Many answers can be found here..." \
  FALSE "Newbie: Linuxrsp" "Windows/Linux software comparison" \
  FALSE "Newbie: LinuxAlternative" "Windows/Linux software comparison" \
  FALSE "Newbie: Grokdoc" "Windows/Linux desktops software comparison" \
  FALSE "Docu: command sheet" "Practical bash reference summary sheet" \
  FALSE "Docu: man-pages" "Terminal command line information" \
  FALSE "Docu: Linux Rute" "Generic Linux tutorial" \
  FALSE "Docu: TLDP" "Howtos, guides, etc. in many languages" \
  FALSE "Docu: DIE" "Howtos, bash, guides, etc." \
  FALSE "Docu: Linux in a Nutshell" "All about the Linux operating system" \
  FALSE "Docu: Linuxtopia" "Howtos, guides, etc." \
  FALSE "Docu: Linux Questions" "Advanced Linux user forum" \
  FALSE "Books: FreeComputerBooks" "Wide variety of programming books" \
  FALSE "Books: OnlineProgBooks" "Free Linux ebooks (online/pdf)" \
  FALSE "Tools: YouTube mp3" "Convert audiotrack to mp3" \
  FALSE "Tools: TinyPic" "Upload images & videos" );
  
  # Quit if Cancel was pressed
  if [ "$GOO_LANG" == "" ]; then 
    exit 0
  fi
  
  # get selected option and open respective website
  index=0
  while [ $index -lt $count ]; do
    if [ "$GOO_LANG" == "${OOLOCT[$index]}" ];then tt=${OOLOC[$index]};fi
    let "index++"
  done
  $wwwb $tt &
done
exit 0
