Advertisement
torbjoernk

Untitled

Jul 11th, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //*********************************************************************
  2. //**** main.cppp *****
  3. //*********************************************************************
  4. #include <KApplication>
  5. #include <KAboutData>
  6. #include <KCmdLineArgs>
  7. #include <KLocale>
  8.  
  9. #include "kbackupview.h"
  10.  
  11. static const char version[] = "0.1";
  12.  
  13.  
  14. int main(int argc, char *argv[])
  15. {
  16.     KAboutData aboutData([...]);
  17.        
  18.         KCmdLineArgs::init(argc, argv, &aboutData);
  19.         KApplication app;
  20.        
  21.         Kbackupview* window = new Kbackupview();
  22.         window->show();
  23.        
  24.         return app.exec();
  25. }
  26.  
  27. //*********************************************************************
  28. //**** kbackupview.h ****
  29. //*********************************************************************
  30. #ifndef KBACKUPVIEW_H
  31. #define KBACKUPVIEW_H
  32.  
  33. #include <KDialog>
  34. #include <KApplication>
  35. #include <KAction>
  36. #include <KLocale>
  37. #include <KActionCollection>
  38. #include <KStandardAction>
  39. #include <KFileDialog>
  40. #include <KMessageBox>
  41. #include <KIO/NetAccess>
  42. #include <QTextStream>
  43.  
  44. // include the automatically generated header file for the ui-file
  45. #include "ui_kbackup.h"
  46.  
  47. class Kbackupview : public KDialog
  48. {
  49.     Q_OBJECT
  50. public:
  51.     Kbackupview(QMainWindow *parent=0);
  52. //    ~Kbackupview();
  53.    
  54. private slots:
  55.     void kdeCfgSlctKdeDestDir();
  56.    
  57. private:
  58.     Ui::Kbackup ui;
  59.    
  60.     QString kdeDestDir; // KDE directory on destination
  61. };
  62.  
  63. #endif
  64.  
  65. //*********************************************************************
  66. //**** kbackupview.cpp ****
  67. //*********************************************************************
  68. // include the header file of the dialog
  69. #include "kbackupview.h"
  70.  
  71. Kbackupview::Kbackupview(QMainWindow* parent)
  72.     : KDialog(parent),
  73.     kdeDestDir(QString())
  74. {
  75.     QMainWindow *widget = new QMainWindow(this);
  76.    
  77.     // create the user interface, the parent widget is "widget"
  78.     ui.setupUi(widget); // this is the important part
  79.    
  80.     // set the widget with all its gui elements as the dialog's main widget
  81.     setMainWidget(widget);
  82.    
  83.     // other KDialog options
  84.     setCaption(i18nc("", "The main window of Kbackup"));
  85.     setButtons(KDialog::Close);
  86.    
  87.     // Example Signal/Slot connection using widgets in your UI.
  88.     // Note that you have to prepend "ui." when referring to your UI elements.
  89.     connect(ui.kdeCfgSlctKdeDestDir, SIGNAL(clicked()), this, SLOT(kdeCfgSlctKdeDestDir()));
  90. }
  91.  
  92. //Kbackupview::~Kbackupview() {
  93. //    
  94. //}
  95.  
  96. void Kbackupview::kdeCfgSlctKdeDestDir()
  97. {
  98.     // ask the user to select a directory
  99.     QString dirNameFromDialog = KFileDialog::getExistingDirectory(KUrl::fromPath("~/"), this, i18nc("", "Select Destination KDE Directory"));
  100.    
  101.     // check of availability of selected directory
  102.     // if available:
  103.     if (!dirNameFromDialog.isEmpty()) {
  104.         // save the selected directory in our variable
  105.         kdeDestDir = dirNameFromDialog;
  106.         // display the selected directory in the LineEdit
  107.         ui.kdeCfgKdeDestDir->setText(kdeDestDir);
  108.        
  109.     // else:
  110.     } else {
  111.         // display error message
  112.         KMessageBox::error(this, i18nc("", "Could not find the selected directory."));
  113.     }
  114. }
  115.  
  116. //*********************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement