pub unsafe fn load_new_tip_dialog(&self, edit: bool) -> Result<()> {

        let view = if cfg!(debug_assertions) { VIEW_DEBUG } else { VIEW_RELEASE };
        let template_path = format!("{}/{}", ASSETS_PATH.to_string_lossy(), view);
        let mut data = vec!();
        let mut file = BufReader::new(File::open(template_path)?);
        file.read_to_end(&mut data)?;

        let ui_loader = QUiLoader::new_0a();
        let main_widget = ui_loader.load_bytes_with_parent(&data, &self.list);

        let user_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "user_label")?;
        let tip_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "tip_label")?;
        let path_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "path_label")?;
        let link_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "link_label")?;

        let button_box: QPtr<QDialogButtonBox> = find_widget(&main_widget.static_upcast(), "button_box")?;
        let user_line_edit: QPtr<QLineEdit> = find_widget(&main_widget.static_upcast(), "user_line_edit")?;
        let link_line_edit: QPtr<QLineEdit> = find_widget(&main_widget.static_upcast(), "link_line_edit")?;
        let path_line_edit: QPtr<QLineEdit> = find_widget(&main_widget.static_upcast(), "path_line_edit")?;
        let tip_text_edit: QPtr<QTextEdit> = find_widget(&main_widget.static_upcast(), "tip_text_edit")?;

        let dialog = main_widget.static_downcast::<QDialog>();
        button_box.button(StandardButton::Cancel).released().connect(dialog.slot_close());
        button_box.button(StandardButton::Ok).released().connect(dialog.slot_accept());

        // Setup data.
        if edit {
            let tip = self.get_tip_from_selection();
            user_line_edit.set_text(&QString::from_std_str(tip.get_ref_user()));
            link_line_edit.set_text(&QString::from_std_str(tip.get_ref_url()));
            tip_text_edit.set_text(&QString::from_std_str(tip.get_ref_message()));
            path_line_edit.set_text(&QString::from_std_str(tip.get_ref_path()));
        } else {
            path_line_edit.set_text(&QString::from_std_str(self.path.read().unwrap().join("/")));
            user_line_edit.set_text(&QString::from_std_str("Daniel, the Demon Prince"));
        }

        // Setup translations.
        dialog.set_window_title(&qtr("new_tip_dialog"));
        user_label.set_text(&qtr("new_tip_user"));
        tip_label.set_text(&qtr("new_tip_tip"));
        path_label.set_text(&qtr("new_tip_path"));
        link_label.set_text(&qtr("new_tip_link"));

        // If we hit accept, build the tip and save it.
        if dialog.exec() == 1 {
            let mut tip = Tip::default();
            tip.set_user(user_line_edit.text().to_std_string());
            tip.set_message(tip_text_edit.to_plain_text().to_std_string());
            tip.set_url(link_line_edit.text().to_std_string());
            tip.set_path(path_line_edit.text().to_std_string());

            // If it's an edit, overwrite the default id with the old one.
            if edit {
                let old_tip = self.get_tip_from_selection();
                tip.set_id(*old_tip.get_ref_id());

                let indexes = self.filter.map_selection_to_source(&self.list.selection_model().selection()).indexes();
                self.model.remove_row_1a(indexes.at(0).row());
            }

            self.save_data(tip);
        }

        Ok(())
    }
/// This function loads the new tip dialog, and returns an error if it fails for any reason.
This function loads the new tip dialog, and returns an error if it fails for any reason.
This function loads the new tip dialog and returns an error if it fails for any reason .
pub unsafe fn load_new_tip_dialog(&self, edit: bool) -> Result<()> {
        let view = if cfg!(debug_assertions) { VIEW_DEBUG } else { VIEW_RELEASE };
        let template_path = format!("{}/{}", ASSETS_PATH.to_string_lossy(), view);
        let mut data = vec!();
        let mut file = BufReader::new(File::open(template_path)?);
        file.read_to_end(&mut data)?;
        let ui_loader = QUiLoader::new_0a();
        let main_widget = ui_loader.load_bytes_with_parent(&data, &self.list);
        let user_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "user_label")?;
        let tip_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "tip_label")?;
        let path_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "path_label")?;
        let link_label: QPtr<QLabel> = find_widget(&main_widget.static_upcast(), "link_label")?;
        let button_box: QPtr<QDialogButtonBox> = find_widget(&main_widget.static_upcast(), "button_box")?;
        let user_line_edit: QPtr<QLineEdit> = find_widget(&main_widget.static_upcast(), "user_line_edit")?;
        let link_line_edit: QPtr<QLineEdit> = find_widget(&main_widget.static_upcast(), "link_line_edit")?;
        let path_line_edit: QPtr<QLineEdit> = find_widget(&main_widget.static_upcast(), "path_line_edit")?;
        let tip_text_edit: QPtr<QTextEdit> = find_widget(&main_widget.static_upcast(), "tip_text_edit")?;
        let dialog = main_widget.static_downcast::<QDialog>();
        button_box.button(StandardButton::Cancel).released().connect(dialog.slot_close());
        button_box.button(StandardButton::Ok).released().connect(dialog.slot_accept());
        // Setup data.
        if edit {
            let tip = self.get_tip_from_selection();
            user_line_edit.set_text(&QString::from_std_str(tip.get_ref_user()));
            link_line_edit.set_text(&QString::from_std_str(tip.get_ref_url()));
            tip_text_edit.set_text(&QString::from_std_str(tip.get_ref_message()));
            path_line_edit.set_text(&QString::from_std_str(tip.get_ref_path()));
        } else {
            path_line_edit.set_text(&QString::from_std_str(self.path.read().unwrap().join("/")));
            user_line_edit.set_text(&QString::from_std_str("Daniel, the Demon Prince"));
        }
        // Setup translations.
        dialog.set_window_title(&qtr("new_tip_dialog"));
        user_label.set_text(&qtr("new_tip_user"));
        tip_label.set_text(&qtr("new_tip_tip"));
        path_label.set_text(&qtr("new_tip_path"));
        link_label.set_text(&qtr("new_tip_link"));
        // If we hit accept, build the tip and save it.
        if dialog.exec() == 1 {
            let mut tip = Tip::default();
            tip.set_user(user_line_edit.text().to_std_string());
            tip.set_message(tip_text_edit.to_plain_text().to_std_string());
            tip.set_url(link_line_edit.text().to_std_string());
            tip.set_path(path_line_edit.text().to_std_string());
            // If it's an edit, overwrite the default id with the old one.
            if edit {
                let old_tip = self.get_tip_from_selection();
                tip.set_id(*old_tip.get_ref_id());
                let indexes = self.filter.map_selection_to_source(&self.list.selection_model().selection()).indexes();
                self.model.remove_row_1a(indexes.at(0).row());
            }
            self.save_data(tip);
        }
        Ok(())
    }
pub unsafe fn load_new_tip_dialog ( & self , edit : bool ) -> Result < ( ) > { let view = if cfg ! ( debug_assertions ) { VIEW_DEBUG } else { VIEW_RELEASE } ; let template_path = format ! ( " " ASSETS_PATH to_string_lossy ( ) view ) ; let mut data = vec ! ( ) ; let mut file = BufReader :: new ( File :: open ( template_path ) ? ) ; file . read_to_end ( & mut data ) ? ; let ui_loader = QUiLoader :: new_0a ( ) ; let main_widget = ui_loader . load_bytes_with_parent ( & data , & self . list ) ; let user_label : QPtr < QLabel > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let tip_label : QPtr < QLabel > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let path_label : QPtr < QLabel > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let link_label : QPtr < QLabel > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let button_box : QPtr < QDialogButtonBox > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let user_line_edit : QPtr < QLineEdit > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let link_line_edit : QPtr < QLineEdit > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let path_line_edit : QPtr < QLineEdit > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let tip_text_edit : QPtr < QTextEdit > = find_widget ( & main_widget . static_upcast ( ) , " " ) ? ; let dialog = main_widget . static_downcast :: < QDialog > ( ) ; button_box . button ( StandardButton :: Cancel ) . released ( ) . connect ( dialog . slot_close ( ) ) ; button_box . button ( StandardButton :: Ok ) . released ( ) . connect ( dialog . slot_accept ( ) ) ; // Setup data. if edit { let tip = self . get_tip_from_selection ( ) ; user_line_edit . set_text ( & QString :: from_std_str ( tip . get_ref_user ( ) ) ) ; link_line_edit . set_text ( & QString :: from_std_str ( tip . get_ref_url ( ) ) ) ; tip_text_edit . set_text ( & QString :: from_std_str ( tip . get_ref_message ( ) ) ) ; path_line_edit . set_text ( & QString :: from_std_str ( tip . get_ref_path ( ) ) ) ; } else { path_line_edit . set_text ( & QString :: from_std_str ( self . path . read ( ) . unwrap ( ) . join ( " " ) ) ) ; user_line_edit . set_text ( & QString :: from_std_str ( " " ) ) ; } // Setup translations. dialog . set_window_title ( & qtr ( " " ) ) ; user_label . set_text ( & qtr ( " " ) ) ; tip_label . set_text ( & qtr ( " " ) ) ; path_label . set_text ( & qtr ( " " ) ) ; link_label . set_text ( & qtr ( " " ) ) ; // If we hit accept, build the tip and save it. if dialog . exec ( ) == 1 { let mut tip = Tip :: default ( ) ; tip . set_user ( user_line_edit . text ( ) . to_std_string ( ) ) ; tip . set_message ( tip_text_edit . to_plain_text ( ) . to_std_string ( ) ) ; tip . set_url ( link_line_edit . text ( ) . to_std_string ( ) ) ; tip . set_path ( path_line_edit . text ( ) . to_std_string ( ) ) ; // If it's an edit, overwrite the default id with the old one. if edit { let old_tip = self . get_tip_from_selection ( ) ; tip . set_id ( * old_tip . get_ref_id ( ) ) ; let indexes = self . filter . map_selection_to_source ( & self . list . selection_model ( ) . selection ( ) ) . indexes ( ) ; self . model . remove_row_1a ( indexes . at ( 0 ) . row ( ) ) ; } self . save_data ( tip ) ; } Ok ( ( ) ) }
This function loads the new tip dialog, and returns an error if it fails for any reason.
This function loads the new tip dialog and returns an error if it fails for any reason .
&self
edit
bool
&self
edit
bool